Skip to content

Instantly share code, notes, and snippets.

@DominicWatts
DominicWatts / Phpcs-disable-exclude-cheatsheet-markup-tags-cheatsheet
Last active September 12, 2024 15:56
PHP : Phpcs disable exclude cheatsheet markup tags cheatsheet #php
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
// phpcs:disable Magento2.Files.LineLength.MaxExceeded
// phpcs:disable Magento2.Files.LineLength
// phpcs:disable Generic
// phpcs:disable Generic.Files.LineLength
/* @noEscape */
// phpcs:ignoreFile
@DominicWatts
DominicWatts / magento-2-escaping-phtml
Last active September 12, 2024 13:56
Magento 2 : Escaping phtml #magento2
public function escapeHtml($data, $allowedTags = null)
public function escapeHtmlAttr($string, $escapeSingleQuote = true)
public function escapeUrl($string)
public function encodeUrlParam($string)
public function escapeJs($string)
public function escapeCss($string)
$block->escapeHtml(__(""));
<?= $block->escapeHtml(__("")); ?>
@DominicWatts
DominicWatts / useful-aliases
Last active September 12, 2024 15:46
Misc : Useful aliases #misc
alias magento-command='docker-compose run --rm cli magento-command'
alias dcud='docker-compose up -d'
alias dcdv='docker-compose down -v'
alias dcd='docker-compose down'
alias dcr='docker-compose restart'
alias dreload='docker compose down -v; docker-compose pull; docker-compose up -d'
alias cli='docker-compose run --rm cli'
alias installer='docker-compose run --rm cli magento-extension-installer'
alias csf-nodoc='docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --verbose --using-cache=no --rules=phpdoc_no_package,ordered_imports ./'
alias csf-m2='docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --rules='\''{"@PSR2":true,"array_syntax":{"syntax":"short"},"concat_space":{"spacing":"one"},"include":true,"new_with_braces":true,"no_empty_statement":true,"no_extra_consecutive_blank_lines":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_multiline_whitespace_around_double_arrow":true,"no_multiline_whitespace_before_semicolons":true,"no_singleline_whitesp
@DominicWatts
DominicWatts / magento-2-phpcs-docker
Last active September 12, 2024 15:51
Magento 2 : PHPCS docker #magento2
docker run --rm -v $PWD:/code domw/phpcs phpcs --colors --standard=Magento2 --report=full,summary --extensions=php,phtml ./
# hide warnings
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#hiding-warnings-by-default
phpcs --error-severity=1 --warning-severity=0 /path/to/code
--config-set warning_severity 0
@DominicWatts
DominicWatts / php-cs-fixer-no-doc
Created February 21, 2020 21:44
Docker : php-cs-fixer no doc #docker
docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --verbose --using-cache=no --rules=phpdoc_no_package,ordered_imports ./
@DominicWatts
DominicWatts / magento-2-phpcbf-docker
Created February 21, 2020 21:46
Magento 2 : PHPCBF docker #magento2
docker run --rm -v $PWD:/code domw/phpcs phpcbf --colors --standard=Magento2 --report=full,summary --extensions=php,phtml ./
@DominicWatts
DominicWatts / php-cs-fixer-magento-2-ruleset-docker
Last active September 12, 2024 15:56
Docker : PHP-CS-Fixer Magento 2 ruleset docker #docker
docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --rules='\''{"@PSR2":true,"array_syntax":{"syntax":"short"},"concat_space":{"spacing":"one"},"include":true,"new_with_braces":true,"no_empty_statement":true,"no_extra_blank_lines":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_multiline_whitespace_around_double_arrow":true,"multiline_whitespace_before_semicolons":false,"no_singleline_whitespace_before_semicolons":true,"no_trailing_comma_in_singleline_array":true,"no_unused_imports":true,"no_whitespace_in_blank_line":true,"object_operator_without_whitespace":true,"ordered_imports":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"phpdoc_no_package":true}'\'' --using-cache=no --allow-risky=yes --verbose
@DominicWatts
DominicWatts / php-cs-fixer-custom-ruleset-docker
Last active September 12, 2024 15:56
Docker : PHP CS Fixer Custom Ruleset Docker #docker
docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --rules=ordered_imports ./
docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --rules='{"@PSR2":true,"array_syntax":{"syntax":"short"},"concat_space":{"spacing":"one"},"ordered_imports":true,"blank_line_after_opening_tag":true,"comment_to_phpdoc":true,"ereg_to_preg":true,"fully_qualified_strict_types":true,"include":true,"linebreak_after_opening_tag":true,"logical_operators":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_consecutive_blank_lines":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_php4_constructor":true,"no_unused_imports":true,"no_useless_else":true,"no_useless_return":true,"normalize_index_brace":true,"phpdoc_add_missing_param_annotation":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_order":true,"phpdoc_return_self_reference":true,"phpdoc_
@DominicWatts
DominicWatts / composer-cheatsheet
Last active September 12, 2024 13:44
Composer : Composer cheatsheet #composer
composer require vendor/module
composer global global vendor/module
composer require vendor/module:1.0.1
composer require vendor/module:^1.0.*
composer require vendor/module --update-no-dev
composer require vendor/module --update-no-dev --ignore-platform-reqs
composer require vendor/module --with-all-dependencies
composer install --no-dev
composer install --no-dev --prefer-dist
@DominicWatts
DominicWatts / Ternary-Operators
Created February 22, 2020 00:35
PHP : Ternary Operators (?:) #php
## most basic usage
$var > 2 ? true : false
## another basic usage
$message = 'Hello '.($user->is_logged_in() ? $user->get('first_name') : 'Guest');
## shorthand usage
$message = 'Hello '.($user->get('first_name') ?: 'Guest');
## echo, inline