Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #14 from bitExpert/feature/phpstan
Browse files Browse the repository at this point in the history
Add PHPStan dependency
  • Loading branch information
shochdoerfer authored Jan 23, 2021
2 parents b860ccb + 93dff2b commit d0f7cfa
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
8 changes: 8 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
</exec>
</target>

<target name="analyse">
<exec executable="./vendor/bin/phpstan"
passthru="true"
checkreturn="true">
<arg value="analyze"/>
</exec>
</target>

<target name="lint">
<phplint>
<fileset dir="${phing.dir}/src">
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
62 changes: 61 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 7
paths:
- src

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ListApiEndpoints extends AbstractMagentoCommand
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('api:list:endpoints')
Expand Down Expand Up @@ -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);

Expand All @@ -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<string, array<string, array<string, array<string, string>>>>
*/
protected function getDefinedServices()
{
Expand All @@ -90,8 +94,9 @@ protected function getDefinedServices()
}

/**
* @param array $services
* @param array<string, array<string, array<string, array<string, string>>>> $services
* @param OutputInterface $output
* @return void
*/
private function printAsTable(array $services, OutputInterface $output)
{
Expand All @@ -118,26 +123,26 @@ 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<string, array<string, array<string, array<string, string>>>> $services
* @param string $methodsToFilter
* @param string $routesToFilter
* @return array
* @return array<string, array<string, array<string, array<string, string>>>>
*/
private function filterServices(array $services, $methodsToFilter, $routesToFilter)
{
if (!isset($services['routes']) || !is_array($services['routes'])) {
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]);
}
}
}

if (!empty($methodsToFilter)) {
if (is_string($methodsToFilter) && !empty($methodsToFilter)) {
$methodsToFilterArray = explode(',', strtoupper($methodsToFilter));
array_walk($methodsToFilterArray, function (&$value, $index) {
$value = trim($value);
Expand Down

0 comments on commit d0f7cfa

Please sign in to comment.