Skip to content

Commit

Permalink
Merge v1.x to master (nunomaduro#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibbarth authored Feb 14, 2021
1 parent eed341b commit 4f3ad38
Show file tree
Hide file tree
Showing 29 changed files with 14,927 additions and 109 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v1.14.1]
### Changed
- Switch service to discover vulnerabilities ([#453](https://github.com/nunomaduro/phpinsights/pull/453))


## [v1.14.0]
### Added
- `ddd` & `tinker` as forbidden method names Laravel ([#364](https://github.com/nunomaduro/phpinsights/pull/364))
Expand Down
23 changes: 15 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"name": "nunomaduro/phpinsights",
"description": "Instant PHP quality checks from your console.",
"keywords": ["php", "insights", "console", "quality", "source", "code"],
"keywords": [
"php",
"insights",
"console",
"quality",
"source",
"code"
],
"license": "MIT",
"authors": [
{
Expand All @@ -24,23 +31,23 @@
"phploc/phploc": "^5.0|^6.0|^7.0",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0",
"sensiolabs/security-checker": "^6.0",
"slevomat/coding-standard": "^6.0",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^4.4|^5.0",
"symfony/console": "^4.2|^5.0",
"symfony/finder": "^4.2|^5.0"
"symfony/finder": "^4.2|^5.0",
"symfony/http-client": "^4.3|^5.0"
},
"require-dev": {
"ergebnis/phpstan-rules": "^0.14.0",
"illuminate/console": "^5.8|^6.0|^7.0",
"illuminate/support": "^5.8|^6.0|^7.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.7.11",
"rector/rector-prefixed": "^0.9.19",
"symfony/var-dumper": "^4.2|^5.0",
"symplify/easy-coding-standard": "^7.2.3",
"symplify/easy-coding-standard": "^9.1",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
},
"suggest": {
Expand Down Expand Up @@ -74,7 +81,7 @@
"scripts": {
"website:copy-changelog": "@php -r \"copy('CHANGELOG.md', 'docs/changelog.md');\"",
"website:copy-logo": "@php -r \"(is_dir('docs/.vuepress/public') || mkdir('docs/.vuepress/public')) && copy('art/logo_mixed.gif', 'docs/.vuepress/public/logo.gif') && copy('art/heart.svg', 'docs/.vuepress/public/heart.svg') && copy('art/heart.png', 'docs/.vuepress/public/heart.png');\"",
"ecs:test": "ecs check src --ansi --config vendor/symplify/easy-coding-standard/config/set/clean-code.yaml",
"ecs:test": "ecs check src --ansi --config vendor/symplify/easy-coding-standard/config/set/clean-code.php",
"phpstan:test": "phpstan analyse --ansi",
"phpunit:test": "phpunit --colors=always",
"rector:test": "rector process --ansi",
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phpinsights",
"version": "1.14.0",
"version": "1.14.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
Expand Down
40 changes: 40 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/bin']);
$parameters->set(Option::AUTOLOAD_PATHS, [
__DIR__ . '/vendor/squizlabs/php_codesniffer/autoload.php',
]);

$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);

// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
// Run Rector only on changed files
$parameters->set(Option::ENABLE_CACHE, true);

// Path to phpstan with extensions, that PHPSTan in Rector uses to determine types
//$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan.neon.dist');

$parameters->set(Option::SETS, [
SetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::DOCTRINE_CODE_QUALITY,
SetList::EARLY_RETURN,
SetList::PHP_71,
SetList::PHP_72,
SetList::PHP_73,
SetList::PHP_74,
SetList::PHPUNIT_CODE_QUALITY,
]);
};
29 changes: 0 additions & 29 deletions rector.yaml

This file was deleted.

6 changes: 4 additions & 2 deletions src/Application/Adapters/Laravel/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public static function shouldBeApplied(Composer $composer): bool
$requirements = $composer->getRequirements();

foreach (array_keys($requirements) as $requirement) {
if (strpos($requirement, 'laravel/framework') !== false
|| strpos($requirement, 'illuminate/') !== false) {
if (strpos($requirement, 'laravel/framework') !== false) {
return true;
}
if (strpos($requirement, 'illuminate/') !== false) {
return true;
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/Application/Adapters/Magento2/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ public static function shouldBeApplied(Composer $composer): bool
$requirements = $composer->getRequirements();

foreach (array_keys($requirements) as $requirement) {
if (strpos($requirement, 'magento/magento-cloud-metapackage') !== false
|| strpos($requirement, 'magento/product-community-edition') !== false
|| strpos($requirement, 'magento/product-enterprise-edition') !== false) {
if (strpos($requirement, 'magento/magento-cloud-metapackage') !== false) {
return true;
}
if (strpos($requirement, 'magento/product-community-edition') !== false) {
return true;
}
if (strpos($requirement, 'magento/product-enterprise-edition') !== false) {
return true;
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/Application/Adapters/Symfony/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ public static function shouldBeApplied(Composer $composer): bool
$requirements = $composer->getRequirements();

foreach (array_keys($requirements) as $requirement) {
if (strpos($requirement, 'symfony/framework-bundle') !== false
|| strpos($requirement, 'symfony/flex') !== false
|| strpos($requirement, 'symfony/symfony') !== false) {
if (strpos($requirement, 'symfony/framework-bundle') !== false) {
return true;
}
if (strpos($requirement, 'symfony/flex') !== false) {
return true;
}
if (strpos($requirement, 'symfony/symfony') !== false) {
return true;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Application/ConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ private static function getComposer(InputInterface $input, string $path): Compos
if ($composerPath === null) {
$composerPath = rtrim($path, '/') . DIRECTORY_SEPARATOR . self::COMPOSER_FILENAME;
}

if (strpos($composerPath, self::COMPOSER_FILENAME) === false || ! file_exists($composerPath)) {
if (strpos($composerPath, self::COMPOSER_FILENAME) === false) {
return new Composer([]);
}
if (! file_exists($composerPath)) {
return new Composer([]);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Application/Console/Commands/InternalProcessorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public function __invoke(InputInterface $input, OutputInterface $output): int
}

$files = $this->cache->get($cacheKey, []);
if (! \is_array($files) || \count($files) === 0) {
if (! \is_array($files)) {
return 0;
}
if (\count($files) === 0) {
return 0;
}

Expand Down Expand Up @@ -97,9 +100,7 @@ private function initialize(): void
$loaders = $container->get(InsightLoaderContract::INSIGHT_LOADER_TAG);

// exclude InsightLoader, not used here
$this->insightsLoaders = array_filter($loaders, static function (InsightLoaderContract $loader): bool {
return ! $loader instanceof InsightLoader;
});
$this->insightsLoaders = array_filter($loaders, static fn (InsightLoaderContract $loader): bool => ! $loader instanceof InsightLoader);
}

/**
Expand All @@ -109,10 +110,9 @@ private function initialize(): void
*/
private function loadInsights(string $metricClass): array
{
/** @var HasInsights $metric */
$metric = new $metricClass();

$insights = \array_key_exists(HasInsights::class, class_implements($metricClass))
$insights = $metric instanceof HasInsights
? $metric->getInsights()
: [];

Expand Down Expand Up @@ -155,7 +155,7 @@ private function processFile(SplFileInfo $file): void
{
$cacheKey = 'insights.' . $this->configuration->getCacheKey() . '.' . md5($file->getContents());
// Do not use cache if fix is enabled to force processors to handle it
if ($this->configuration->hasFixEnabled() === false && $this->cache->has($cacheKey)) {
if (! $this->configuration->hasFixEnabled() && $this->cache->has($cacheKey)) {
return;
}

Expand All @@ -170,7 +170,7 @@ private function processFile(SplFileInfo $file): void
$fileProcessor->processFile($file);
}

if ($this->configuration->hasFixEnabled() === true) {
if ($this->configuration->hasFixEnabled()) {
// regenerate cache key in case fixer change contents
$cacheKey = 'insights.' . $this->configuration->getCacheKey() . '.' . md5($file->getContents());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Console/Formatters/Checkstyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function format(InsightCollection $insightCollection, array $metrics): vo
foreach ($details as $detail) {
$fileName = PathShortener::fileName($detail, $insightCollection->getCollector()->getCommonPath());

if (isset($checkstyle->file) && (string) $checkstyle->file->attributes()['name'] === $fileName) {
if (property_exists($checkstyle, 'file') && $checkstyle->file !== null && (string) $checkstyle->file->attributes()['name'] === $fileName) {
$file = $checkstyle->file;
} else {
$file = $checkstyle->addChild('file');
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Console/Formatters/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private function code(InsightCollection $insightCollection, Results $results): s
$lines = [];
foreach (self::CODE_METRIC_CLASSES as $metric) {
$name = explode('\\', $metric);
$lines[(string) end($name)] = (float) (new $metric())->getPercentage($insightCollection->getCollector());
$lines[end($name)] = (float) (new $metric())->getPercentage($insightCollection->getCollector());
}

$this->writePercentageLines($lines);
Expand Down Expand Up @@ -310,7 +310,7 @@ private function architecture(InsightCollection $insightCollection, Results $res
$lines = [];
foreach (self::ARCHITECTURE_METRIC_CLASSES as $metric) {
$name = explode('\\', $metric);
$lines[(string) end($name)] = (float) (new $metric())->getPercentage($insightCollection->getCollector());
$lines[end($name)] = (float) (new $metric())->getPercentage($insightCollection->getCollector());
}

$this->writePercentageLines($lines);
Expand Down
3 changes: 2 additions & 1 deletion src/Domain/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ private function validateAddedInsight(): Closure
return static function ($values): bool {
foreach ($values as $metric => $insights) {
if (! class_exists($metric) ||
class_implements($metric) === false ||
! in_array(Metric::class, class_implements($metric), true)
) {
throw new InvalidConfiguration(sprintf(
Expand Down Expand Up @@ -393,7 +394,7 @@ private function getNumberOfCore(): int
$cpuinfo = file_get_contents('/proc/cpuinfo');
if ($cpuinfo !== false) {
preg_match_all('/^processor/m', $cpuinfo, $matches);
return \count($matches[0]);
return is_countable($matches[0]) ? \count($matches[0]) : 0;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Domain/FileProcessors/FixerFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ public function processFile(SplFileInfo $splFileInfo): void
Tokens::clearCache();
$tokens = clone $originalTokens;
}

if (! $this->fixEnabled || ! $needFix) {
if (! $this->fixEnabled) {
return;
}
if (! $needFix) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Domain/InsightLoader/FixerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ final class FixerLoader implements InsightLoader
{
public function support(string $insightClass): bool
{
if (class_implements($insightClass) === false) {
return false;
}
return array_key_exists(FixerInterface::class, class_implements($insightClass));
}

Expand Down
3 changes: 3 additions & 0 deletions src/Domain/InsightLoader/InsightLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class InsightLoader implements LoaderContract
{
public function support(string $insightClass): bool
{
if (class_implements($insightClass) === false) {
return false;
}
return array_key_exists(Insight::class, class_implements($insightClass));
}

Expand Down
3 changes: 3 additions & 0 deletions src/Domain/InsightLoader/SniffLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ final class SniffLoader implements InsightLoader
{
public function support(string $insightClass): bool
{
if (class_implements($insightClass) === false) {
return false;
}
return array_key_exists(SniffContract::class, class_implements($insightClass));
}

Expand Down
8 changes: 5 additions & 3 deletions src/Domain/Insights/FixerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getTitle(): string
{
$fixerClass = $this->getInsightClass();
$path = explode('\\', $fixerClass);
$name = (string) array_pop($path);
$name = array_pop($path);
$name = str_replace('Fixer', '', $name);

return ucfirst(mb_strtolower(trim((string) preg_replace('/(?<! )[A-Z]/', ' $0', $name))));
Expand Down Expand Up @@ -141,7 +141,9 @@ public function addDiff(string $file, string $diff): void
private function skipFilesFromExcludedFiles(SplFileInfo $file): bool
{
$path = $file->getRealPath();

return $path !== false && isset($this->exclude[$path]);
if ($path === false) {
return false;
}
return isset($this->exclude[$path]);
}
}
Loading

0 comments on commit 4f3ad38

Please sign in to comment.