From 5a7ac89fedce44f015db800bc46315ded7c456b3 Mon Sep 17 00:00:00 2001 From: Muhamad Surya Iksanudin Date: Wed, 4 Aug 2021 09:46:58 +0700 Subject: [PATCH] improve code quality --- .gitignore | 5 + composer.json | 1 + composer.lock | 622 ++++++++++++++++++++- lib/Media/Storage.php | 8 +- lib/Pagination/Paginator.php | 4 +- lib/Repository/MenuRepository.php | 2 +- lib/Repository/PermissionRepository.php | 6 +- lib/Repository/SettingRepository.php | 2 +- lib/Security/Service/MenuService.php | 4 +- lib/Security/Service/PermissionService.php | 2 +- phpcs.xml.dist | 19 + phpinsights.php | 117 ++++ symfony.lock | 36 ++ 13 files changed, 798 insertions(+), 30 deletions(-) create mode 100644 phpcs.xml.dist create mode 100644 phpinsights.php diff --git a/.gitignore b/.gitignore index 7861adc5..8105852d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,8 @@ Caddyfile /phpunit.xml .phpunit.result.cache ###< phpunit/phpunit ### + +###> squizlabs/php_codesniffer ### +/.phpcs-cache +/phpcs.xml +###< squizlabs/php_codesniffer ### diff --git a/composer.json b/composer.json index 5a4d45d5..c8e3f477 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "dg/bypass-finals": ">=1.3", "doctrine/doctrine-fixtures-bundle": ">=3.3", "friendsofphp/php-cs-fixer": ">=2.16", + "nunomaduro/phpinsights": "^2.0", "phpstan/phpstan": "0.12.90", "phpunit/phpunit": ">=9.5", "rector/rector": ">=0.11.20", diff --git a/composer.lock b/composer.lock index b92f7b49..9b95ddff 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fcb15ce736fcd1012dc15cbc0395ea12", + "content-hash": "c469805358bc7a82aeb76566422f3663", "packages": [ { "name": "beberlei/assert", @@ -2600,43 +2600,41 @@ }, { "name": "lcobucci/jwt", - "version": "4.0.3", + "version": "4.1.4", "source": { "type": "git", "url": "https://github.com/lcobucci/jwt.git", - "reference": "ae4165a76848e070fdac691e773243d10cd06ce1" + "reference": "71cf170102c8371ccd933fa4df6252086d144de6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lcobucci/jwt/zipball/ae4165a76848e070fdac691e773243d10cd06ce1", - "reference": "ae4165a76848e070fdac691e773243d10cd06ce1", + "url": "https://api.github.com/repos/lcobucci/jwt/zipball/71cf170102c8371ccd933fa4df6252086d144de6", + "reference": "71cf170102c8371ccd933fa4df6252086d144de6", "shasum": "" }, "require": { + "ext-hash": "*", + "ext-json": "*", "ext-mbstring": "*", "ext-openssl": "*", + "ext-sodium": "*", "lcobucci/clock": "^2.0", "php": "^7.4 || ^8.0" }, "require-dev": { - "infection/infection": "^0.20", + "infection/infection": "^0.21", "lcobucci/coding-standard": "^6.0", - "mikey179/vfsstream": "^1.6", - "phpbench/phpbench": "^0.17", + "mikey179/vfsstream": "^1.6.7", + "phpbench/phpbench": "^1.0@alpha", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-strict-rules": "^0.12", "phpunit/php-invoker": "^3.1", - "phpunit/phpunit": "^9.4" + "phpunit/phpunit": "^9.5" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - } - }, "autoload": { "psr-4": { "Lcobucci\\JWT\\": "src" @@ -2660,7 +2658,7 @@ ], "support": { "issues": "https://github.com/lcobucci/jwt/issues", - "source": "https://github.com/lcobucci/jwt/tree/4.0.3" + "source": "https://github.com/lcobucci/jwt/tree/4.1.4" }, "funding": [ { @@ -2672,7 +2670,7 @@ "type": "patreon" } ], - "time": "2021-03-23T23:47:22+00:00" + "time": "2021-03-23T23:53:08+00:00" }, { "name": "lexik/jwt-authentication-bundle", @@ -10345,6 +10343,76 @@ } ], "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.1", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2020-12-07T18:04:37+00:00" + }, { "name": "dg/bypass-finals", "version": "v1.3.1", @@ -10644,6 +10712,85 @@ ], "time": "2021-08-02T17:57:52+00:00" }, + { + "name": "league/container", + "version": "3.4.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/container.git", + "reference": "84ecbc2dbecc31bd23faf759a0e329ee49abddbd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/container/zipball/84ecbc2dbecc31bd23faf759a0e329ee49abddbd", + "reference": "84ecbc2dbecc31bd23faf759a0e329ee49abddbd", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/container": "^1.0.0" + }, + "provide": { + "psr/container-implementation": "^1.0" + }, + "replace": { + "orno/di": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0 || ^7.0", + "roave/security-advisories": "dev-latest", + "scrutinizer/ocular": "^1.8", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev", + "dev-3.x": "3.x-dev", + "dev-2.x": "2.x-dev", + "dev-1.x": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Container\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Phil Bennett", + "email": "philipobenito@gmail.com", + "homepage": "http://www.philipobenito.com", + "role": "Developer" + } + ], + "description": "A fast and intuitive dependency injection container.", + "homepage": "https://github.com/thephpleague/container", + "keywords": [ + "container", + "dependency", + "di", + "injection", + "league", + "provider", + "service" + ], + "support": { + "issues": "https://github.com/thephpleague/container/issues", + "source": "https://github.com/thephpleague/container/tree/3.4.1" + }, + "funding": [ + { + "url": "https://github.com/philipobenito", + "type": "github" + } + ], + "time": "2021-07-09T08:23:52+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.10.2", @@ -10758,6 +10905,114 @@ }, "time": "2021-07-21T10:44:31+00:00" }, + { + "name": "nunomaduro/phpinsights", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/nunomaduro/phpinsights.git", + "reference": "d07b45bb8add1f608fd007efbb989ecca59e3e96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nunomaduro/phpinsights/zipball/d07b45bb8add1f608fd007efbb989ecca59e3e96", + "reference": "d07b45bb8add1f608fd007efbb989ecca59e3e96", + "shasum": "" + }, + "require": { + "composer/composer": "^2.0", + "ext-iconv": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "friendsofphp/php-cs-fixer": "^3.0.0", + "justinrainbow/json-schema": "^5.1", + "league/container": "^3.2", + "php": "^7.4 || ^8.0", + "php-parallel-lint/php-parallel-lint": "^1.3", + "phploc/phploc": "^5.0|^6.0|^7.0", + "psr/container": "^1.0", + "psr/simple-cache": "^1.0", + "slevomat/coding-standard": "^7.0.8", + "squizlabs/php_codesniffer": "^3.5", + "symfony/cache": "^4.4|^5.0", + "symfony/console": "^4.2|^5.0", + "symfony/finder": "^4.2|^5.0", + "symfony/http-client": "^4.3|^5.0" + }, + "require-dev": { + "ergebnis/phpstan-rules": "^0.15.0", + "illuminate/console": "^5.8|^6.0|^7.0|^8.0", + "illuminate/support": "^5.8|^6.0|^7.0|^8.0", + "mockery/mockery": "^1.0", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^8.0|^9.0", + "rector/rector": "0.11.32", + "symfony/var-dumper": "^4.2|^5.0", + "thecodingmachine/phpstan-strict-rules": "^0.12.0" + }, + "suggest": { + "ext-simplexml": "It is needed for the checkstyle formatter" + }, + "bin": [ + "bin/phpinsights" + ], + "type": "library", + "extra": { + "laravel": { + "providers": [ + "NunoMaduro\\PhpInsights\\Application\\Adapters\\Laravel\\InsightsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "NunoMaduro\\PhpInsights\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Instant PHP quality checks from your console.", + "keywords": [ + "Insights", + "code", + "console", + "php", + "quality", + "source" + ], + "support": { + "issues": "https://github.com/nunomaduro/phpinsights/issues", + "source": "https://github.com/nunomaduro/phpinsights/tree/v2.0.1" + }, + "funding": [ + { + "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L", + "type": "custom" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://github.com/olivernybroe", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2021-07-11T13:33:54+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.3", @@ -10921,6 +11176,124 @@ }, "time": "2020-10-14T08:32:19+00:00" }, + { + "name": "php-parallel-lint/php-parallel-lint", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", + "reference": "772a954e5f119f6f5871d015b23eabed8cbdadfb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/772a954e5f119f6f5871d015b23eabed8cbdadfb", + "reference": "772a954e5f119f6f5871d015b23eabed8cbdadfb", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "replace": { + "grogy/php-parallel-lint": "*", + "jakub-onderka/php-parallel-lint": "*" + }, + "require-dev": { + "nette/tester": "^1.3 || ^2.0", + "php-parallel-lint/php-console-highlighter": "~0.3", + "squizlabs/php_codesniffer": "^3.5" + }, + "suggest": { + "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + }, + "bin": [ + "parallel-lint" + ], + "type": "library", + "autoload": { + "classmap": [ + "./" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "ahoj@jakubonderka.cz" + } + ], + "description": "This tool check syntax of PHP files about 20x faster than serial check.", + "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "support": { + "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.3.0" + }, + "time": "2021-04-07T14:42:48+00:00" + }, + { + "name": "phploc/phploc", + "version": "7.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phploc.git", + "reference": "af0d5fc84f3f7725513ba59cdcbe670ac2a4532a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phploc/zipball/af0d5fc84f3f7725513ba59cdcbe670ac2a4532a", + "reference": "af0d5fc84f3f7725513ba59cdcbe670ac2a4532a", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0", + "sebastian/cli-parser": "^1.0", + "sebastian/version": "^3.0" + }, + "bin": [ + "phploc" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "A tool for quickly measuring the size of a PHP project.", + "homepage": "https://github.com/sebastianbergmann/phploc", + "support": { + "issues": "https://github.com/sebastianbergmann/phploc/issues", + "source": "https://github.com/sebastianbergmann/phploc/tree/7.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-12-07T05:51:20+00:00" + }, { "name": "phpspec/prophecy", "version": "1.13.0", @@ -10988,6 +11361,55 @@ }, "time": "2021-03-17T13:42:18+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "0.5.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "ea0b17460ec38e20d7eb64e7ec49b5d44af5d28c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ea0b17460ec38e20d7eb64e7ec49b5d44af5d28c", + "reference": "ea0b17460ec38e20d7eb64e7ec49b5d44af5d28c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12.87", + "phpstan/phpstan-strict-rules": "^0.12.5", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/0.5.5" + }, + "time": "2021-06-11T13:24:46+00:00" + }, { "name": "phpstan/phpstan", "version": "0.12.90", @@ -11473,6 +11895,57 @@ ], "time": "2021-07-31T15:17:34+00:00" }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/master" + }, + "time": "2017-10-23T01:57:42+00:00" + }, { "name": "rector/rector", "version": "0.11.35", @@ -12496,6 +12969,123 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "7.0.13", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "122a9bf9a4a2195f74100f47dfb8375982f43cc9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/122a9bf9a4a2195f74100f47dfb8375982f43cc9", + "reference": "122a9bf9a4a2195f74100f47dfb8375982f43cc9", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.1 || ^8.0", + "phpstan/phpdoc-parser": "0.5.1 - 0.5.5", + "squizlabs/php_codesniffer": "^3.6.0" + }, + "require-dev": { + "phing/phing": "2.16.4", + "php-parallel-lint/php-parallel-lint": "1.3.0", + "phpstan/phpstan": "0.12.93", + "phpstan/phpstan-deprecation-rules": "0.12.6", + "phpstan/phpstan-phpunit": "0.12.21", + "phpstan/phpstan-strict-rules": "0.12.10", + "phpunit/phpunit": "7.5.20|8.5.5|9.5.7" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/7.0.13" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2021-07-29T14:30:22+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.6.0", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2021-04-09T00:54:41+00:00" + }, { "name": "symfony/css-selector", "version": "v5.3.4", diff --git a/lib/Media/Storage.php b/lib/Media/Storage.php index f269688c..c5e780d9 100755 --- a/lib/Media/Storage.php +++ b/lib/Media/Storage.php @@ -23,7 +23,7 @@ public function upload($obj, PropertyMapping $mapping): void } $file = $mapping->getFile($obj); - if (null === $file || !($file instanceof UploadedFile)) { + if (!($file instanceof UploadedFile)) { throw new LogicException('No uploadable file found'); } @@ -36,7 +36,7 @@ public function upload($obj, PropertyMapping $mapping): void if ( str_contains($file->getMimeType(), 'image/') && 'image/svg+xml' !== $file->getMimeType() && - false !== $dimensions = @getimagesize($file->getRealPath()) + false !== $dimensions = getimagesize($file->getRealPath()) ) { $mapping->writeProperty($obj, 'dimensions', array_splice($dimensions, 0, 2)); } @@ -68,12 +68,12 @@ public function resolveUri($obj, ?string $fieldName = null, ?string $className = } [$mapping, $name] = $this->getFilename($obj, $fieldName, $className); - if (empty($name)) { + if (!$name) { return null; } $uploadDir = $this->convertWindowsDirectorySeparator($mapping->getUploadDir($obj)); - $uploadDir = empty($uploadDir) ? '' : $uploadDir; + $uploadDir = !$uploadDir ? '' : $uploadDir; if ($obj->isPublic()) { $uploadDir = sprintf('%s/%s', MediaInterface::PUBLIC_FIELD, $uploadDir); } diff --git a/lib/Pagination/Paginator.php b/lib/Pagination/Paginator.php index 250eefdb..d4c59c96 100755 --- a/lib/Pagination/Paginator.php +++ b/lib/Pagination/Paginator.php @@ -67,7 +67,7 @@ private function paging(QueryBuilder $queryBuilder, int $page, int $perPage): ar $query = $queryBuilder->getQuery(); $query->useQueryCache(true); - $query->enableResultCache($this->cacheLifetime, sprintf('%s:%s:%s:%s', __CLASS__, __METHOD__, $page, $perPage)); + $query->enableResultCache($this->cacheLifetime, sprintf('%s:%s:%s:%s', self::class, __METHOD__, $page, $perPage)); return $query->getResult(); } @@ -83,7 +83,7 @@ private function count(QueryBuilder $queryBuilder): int $query = $count->getQuery(); $query->useQueryCache(true); - $query->enableResultCache($this->cacheLifetime, sprintf('%s:%s', __CLASS__, __METHOD__)); + $query->enableResultCache($this->cacheLifetime, sprintf('%s:%s', self::class, __METHOD__)); return (int) $query->getSingleScalarResult(); } diff --git a/lib/Repository/MenuRepository.php b/lib/Repository/MenuRepository.php index e1e282e7..8eedca02 100755 --- a/lib/Repository/MenuRepository.php +++ b/lib/Repository/MenuRepository.php @@ -39,7 +39,7 @@ public function findChilds(MenuInterface $menu): iterable $query = $queryBuilder->getQuery(); $query->useQueryCache(true); - $query->enableResultCache(self::MICRO_CACHE, sprintf('%s:%s:%s', __CLASS__, __METHOD__, $menu->getId())); + $query->enableResultCache(self::MICRO_CACHE, sprintf('%s:%s:%s', self::class, __METHOD__, $menu->getId())); return $query->getResult(); } diff --git a/lib/Repository/PermissionRepository.php b/lib/Repository/PermissionRepository.php index dcf3b606..53235b98 100755 --- a/lib/Repository/PermissionRepository.php +++ b/lib/Repository/PermissionRepository.php @@ -52,7 +52,7 @@ public function findPermissions(GroupInterface $group, iterable $menus): iterabl $query->useQueryCache(true); $query->enableResultCache( self::MICRO_CACHE, - sprintf('%s:%s:%s:%s', __CLASS__, __METHOD__, $group->getId(), serialize($ids)) + sprintf('%s:%s:%s:%s', self::class, __METHOD__, $group->getId(), serialize($ids)) ); return $query->getResult(); @@ -79,7 +79,7 @@ public function findAllowedMenusByGroup(GroupInterface $group, bool $parentOnly $query->useQueryCache(true); $query->enableResultCache( self::MICRO_CACHE, - sprintf('%s:%s:%s:%d', __CLASS__, __METHOD__, $group->getId(), (int) $parentOnly) + sprintf('%s:%s:%s:%d', self::class, __METHOD__, $group->getId(), (int) $parentOnly) ); /** @var PermissionInterface[] $permissions */ @@ -109,7 +109,7 @@ public function findAllowedChildMenusByGroupAndMenu(GroupInterface $group, MenuI $query->useQueryCache(true); $query->enableResultCache( self::MICRO_CACHE, - sprintf('%s:%s:%s:%s', __CLASS__, __METHOD__, $group->getId(), $menu->getId()) + sprintf('%s:%s:%s:%s', self::class, __METHOD__, $group->getId(), $menu->getId()) ); /** @var PermissionInterface[] $permissions */ diff --git a/lib/Repository/SettingRepository.php b/lib/Repository/SettingRepository.php index 73349705..709a7a50 100755 --- a/lib/Repository/SettingRepository.php +++ b/lib/Repository/SettingRepository.php @@ -37,7 +37,7 @@ public function findByParameter(string $parameter): ?SettingInterface $query = $queryBuilder->getQuery(); $query->useQueryCache(true); - $query->enableResultCache(self::MICRO_CACHE, sprintf('%s:%s:%s', __CLASS__, __METHOD__, $parameter)); + $query->enableResultCache(self::MICRO_CACHE, sprintf('%s:%s:%s', self::class, __METHOD__, $parameter)); return $query->getOneOrNullResult(); } diff --git a/lib/Security/Service/MenuService.php b/lib/Security/Service/MenuService.php index ebc771c6..b1d9c875 100755 --- a/lib/Security/Service/MenuService.php +++ b/lib/Security/Service/MenuService.php @@ -51,7 +51,7 @@ public function hasChildMenu(MenuInterface $menu): bool } $childMenus = $this->permissionRepository->findAllowedChildMenusByGroupAndMenu($group, $menu); - if (!empty($childMenus)) { + if (0 < count($childMenus)) { return true; } @@ -82,6 +82,6 @@ private function getGroup(): ?GroupInterface return null; } - return $user->getGroup(); + return $group; } } diff --git a/lib/Security/Service/PermissionService.php b/lib/Security/Service/PermissionService.php index 266e7fef..52857c80 100755 --- a/lib/Security/Service/PermissionService.php +++ b/lib/Security/Service/PermissionService.php @@ -121,7 +121,7 @@ private function buildMenu(MenuInterface $menu, GroupInterface $group): array /** @var MenuInterface[] $childs */ $childs = $this->menuRepository->findChilds($menu); - if (!empty($childs)) { + if (0 < count($childs)) { $tree['childs'] = []; $permissions = $this->getPermissions($group, $childs); foreach ($permissions as $key => $permission) { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..0738cd78 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,19 @@ + + + + + + + + + + + + bin/ + config/ + public/ + lib/ + tests/ + + diff --git a/phpinsights.php b/phpinsights.php new file mode 100644 index 00000000..02d93ba0 --- /dev/null +++ b/phpinsights.php @@ -0,0 +1,117 @@ + 'symfony', + + /* + |-------------------------------------------------------------------------- + | IDE + |-------------------------------------------------------------------------- + | + | This options allow to add hyperlinks in your terminal to quickly open + | files in your favorite IDE while browsing your PhpInsights report. + | + | Supported: "textmate", "macvim", "emacs", "sublime", "phpstorm", + | "atom", "vscode". + | + | If you have another IDE that is not in this list but which provide an + | url-handler, you could fill this config with a pattern like this: + | + | myide://open?url=file://%f&line=%l + | + */ + + 'ide' => "phpstorm", + + /* + |-------------------------------------------------------------------------- + | Configuration + |-------------------------------------------------------------------------- + | + | Here you may adjust all the various `Insights` that will be used by PHP + | Insights. You can either add, remove or configure `Insights`. Keep in + | mind, that all added `Insights` must belong to a specific `Metric`. + | + */ + + 'exclude' => [ + 'lib/DataFixtures', + 'lib/Entity', + '*Repository.php', + 'lib/Kernel.php', + 'lib/SemartApiSkeleton.php' + ], + + 'add' => [ + // ExampleMetric::class => [ + // ExampleInsight::class, + // ] + ], + + 'remove' => [ + ForbiddenSetterSniff::class, + EmptyStatementSniff::class, + UselessOverridingMethodSniff::class, + AssignmentInConditionSniff::class, + ], + + 'config' => [ + // ExampleInsight::class => [ + // 'key' => 'value', + // ], + ], + + /* + |-------------------------------------------------------------------------- + | Requirements + |-------------------------------------------------------------------------- + | + | Here you may define a level you want to reach per `Insights` category. + | When a score is lower than the minimum level defined, then an error + | code will be returned. This is optional and individually defined. + | + */ + + 'requirements' => [ +// 'min-quality' => 0, +// 'min-complexity' => 0, +// 'min-architecture' => 0, +// 'min-style' => 0, +// 'disable-security-check' => false, + ], + + /* + |-------------------------------------------------------------------------- + | Threads + |-------------------------------------------------------------------------- + | + | Here you may adjust how many threads (core) PHPInsights can use to perform + | the analyse. This is optional, don't provide it and the tool will guess + | the max core number available. This accept null value or integer > 0. + | + */ + + 'threads' => null, + +]; diff --git a/symfony.lock b/symfony.lock index 775c4c30..3900ba6b 100644 --- a/symfony.lock +++ b/symfony.lock @@ -45,6 +45,9 @@ "config/routes/dh_auditor.yaml" ] }, + "dealerdirect/phpcodesniffer-composer-installer": { + "version": "v0.7.1" + }, "dg/bypass-finals": { "version": "v1.3.1" }, @@ -168,6 +171,9 @@ "lcobucci/jwt": { "version": "3.3.2" }, + "league/container": { + "version": "3.4.1" + }, "lexik/jwt-authentication-bundle": { "version": "2.5", "recipe": { @@ -217,6 +223,9 @@ "nikic/php-parser": { "version": "v4.4.0" }, + "nunomaduro/phpinsights": { + "version": "v2.0.1" + }, "ocramius/package-versions": { "version": "1.4.2" }, @@ -232,6 +241,9 @@ "php-cs-fixer/diff": { "version": "v1.3.0" }, + "php-parallel-lint/php-parallel-lint": { + "version": "v1.3.0" + }, "php-webdriver/webdriver": { "version": "1.11.1" }, @@ -244,9 +256,15 @@ "phpdocumentor/type-resolver": { "version": "1.1.0" }, + "phploc/phploc": { + "version": "7.0.2" + }, "phpspec/prophecy": { "version": "1.13.0" }, + "phpstan/phpdoc-parser": { + "version": "0.5.5" + }, "phpstan/phpstan": { "version": "0.12.88" }, @@ -294,6 +312,9 @@ "psr/log": { "version": "1.1.3" }, + "psr/simple-cache": { + "version": "1.0.1" + }, "ramsey/collection": { "version": "1.0.1" }, @@ -387,6 +408,9 @@ "config/packages/sensio_framework_extra.yaml" ] }, + "slevomat/coding-standard": { + "version": "7.0.13" + }, "snc/redis-bundle": { "version": "2.0", "recipe": { @@ -399,6 +423,18 @@ "config/packages/snc_redis.yaml" ] }, + "squizlabs/php_codesniffer": { + "version": "3.6", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "master", + "version": "3.6", + "ref": "1019e5c08d4821cb9b77f4891f8e9c31ff20ac6f" + }, + "files": [ + "phpcs.xml.dist" + ] + }, "stof/doctrine-extensions-bundle": { "version": "1.2", "recipe": {