From 93dff2b81d97c76c0ed46391d0ddfe6fc3ab7d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Sat, 23 Jan 2021 16:33:17 +0100 Subject: [PATCH] Add PHPStan dependency --- build.xml | 8 +++ composer.json | 3 +- composer.lock | 62 ++++++++++++++++++- phpstan.neon | 5 ++ .../Command/ListApiEndpoints.php | 19 +++--- 5 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 phpstan.neon diff --git a/build.xml b/build.xml index 22c27f9..ca27c18 100644 --- a/build.xml +++ b/build.xml @@ -10,6 +10,14 @@ + + + + + + diff --git a/composer.json b/composer.json index 8abc78e..8ca9690 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "n98/magerun2": "^4.0.0", "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.5", - "phing/phing": "^2.16" + "phing/phing": "^2.16", + "phpstan/phpstan": "^0.12.68" }, "repositories": [ { diff --git a/composer.lock b/composer.lock index e96e94b..5f7241b 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": "5721ee9dc3f71800052c98c1a3082423", + "content-hash": "855844197a7929c42b0c3c906054d761", "packages": [ { "name": "colinmollenhour/credis", @@ -6992,6 +6992,66 @@ ], "time": "2020-12-19T10:15:11+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.68", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "ddbe01af0706ee094c3f1ce9730b35aebb508d3d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ddbe01af0706ee094c3f1ce9730b35aebb508d3d", + "reference": "ddbe01af0706ee094c3f1ce9730b35aebb508d3d", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.68" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-01-18T12:29:17+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.5", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..97f8c70 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 7 + paths: + - src + diff --git a/src/BitExpert/Magento/ListApiEndpoints/Command/ListApiEndpoints.php b/src/BitExpert/Magento/ListApiEndpoints/Command/ListApiEndpoints.php index e0eaace..4576686 100644 --- a/src/BitExpert/Magento/ListApiEndpoints/Command/ListApiEndpoints.php +++ b/src/BitExpert/Magento/ListApiEndpoints/Command/ListApiEndpoints.php @@ -28,7 +28,7 @@ class ListApiEndpoints extends AbstractMagentoCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName('api:list:endpoints') @@ -64,7 +64,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->detectMagento($output); if ($this->initMagento()) { $methodFilter = $input->getOption(self::OPTION_FILTER_METHOD); + $methodFilter = is_string($methodFilter) ? $methodFilter : ''; $routeFilter = $input->getOption(self::OPTION_FILTER_ROUTE); + $routeFilter = is_string($routeFilter) ? $routeFilter : ''; $services = $this->getDefinedServices(); $services = $this->filterServices($services, $methodFilter, $routeFilter); @@ -77,10 +79,12 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new InvalidArgumentException('Selected output-format is not a valid option'); } } + + return 0; } /** - * @return array + * @return array>>> */ protected function getDefinedServices() { @@ -90,8 +94,9 @@ protected function getDefinedServices() } /** - * @param array $services + * @param array>>> $services * @param OutputInterface $output + * @return void */ private function printAsTable(array $services, OutputInterface $output) { @@ -118,10 +123,10 @@ private function printAsTable(array $services, OutputInterface $output) * Remove routes from given $services array that do not match given $methodsToFilter. $methodsToFilter can * contain a single HTTP method like GET or POST or multiple ones separated by a comma. * - * @param array $services + * @param array>>> $services * @param string $methodsToFilter * @param string $routesToFilter - * @return array + * @return array>>> */ private function filterServices(array $services, $methodsToFilter, $routesToFilter) { @@ -129,7 +134,7 @@ private function filterServices(array $services, $methodsToFilter, $routesToFilt return $services; } - if (!empty($routesToFilter)) { + if (is_string($routesToFilter) && !empty($routesToFilter)) { foreach ($services['routes'] as $route => $methods) { if (strpos($route, $routesToFilter) === false) { unset($services['routes'][$route]); @@ -137,7 +142,7 @@ private function filterServices(array $services, $methodsToFilter, $routesToFilt } } - if (!empty($methodsToFilter)) { + if (is_string($methodsToFilter) && !empty($methodsToFilter)) { $methodsToFilterArray = explode(',', strtoupper($methodsToFilter)); array_walk($methodsToFilterArray, function (&$value, $index) { $value = trim($value);