From 58b18c1f55dfbbda07a6be1facacdacf2b268716 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 22:07:56 +0200 Subject: [PATCH 01/10] fix: "Cannot declare class because the name is already in use" errors --- src/Automatic/Automatic.php | 43 +++++++++------------------------ src/Security/SecurityPlugin.php | 24 +++++++----------- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/src/Automatic/Automatic.php b/src/Automatic/Automatic.php index 232a8b19..e81594aa 100644 --- a/src/Automatic/Automatic.php +++ b/src/Automatic/Automatic.php @@ -54,34 +54,24 @@ use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; -class Automatic implements PluginInterface, EventSubscriberInterface +class Automatic implements EventSubscriberInterface, PluginInterface { use ExpandTargetDirTrait; use GetGenericPropertyReaderTrait; - /** - * @var string - */ + /** @var string */ public const VERSION = '0.12.0'; - /** - * @var string - */ + /** @var string */ public const LOCK_CLASSMAP = 'classmap'; - /** - * @var string - */ + /** @var string */ public const LOCK_PACKAGES = 'packages'; - /** - * @var string - */ + /** @var string */ public const PACKAGE_NAME = 'narrowspark/automatic'; - /** - * @var string - */ + /** @var string */ public const COMPOSER_EXTRA_KEY = 'automatic'; /** @@ -206,11 +196,11 @@ public function activate(Composer $composer, IOInterface $io): void } // to avoid issues when Automatic is upgraded, we load all PHP classes now - // that way, we are sure to use all files from the same version. + // that way, we are sure to use all classes from the same version. foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\dirname(__DIR__, 1), FilesystemIterator::SKIP_DOTS)) as $file) { /** @var \SplFileInfo $file */ if (\substr($file->getFilename(), -4) === '.php') { - require_once $file; + class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__), -4))); } } @@ -313,15 +303,13 @@ public function initAutoScripts(): void $autoScript = '@' . ScriptEvents::AUTO_SCRIPTS; - if (isset($scripts[ComposerScriptEvents::POST_INSTALL_CMD], $scripts[ComposerScriptEvents::POST_UPDATE_CMD]) && - \in_array($autoScript, $scripts[ComposerScriptEvents::POST_INSTALL_CMD], true) && - \in_array($autoScript, $scripts[ComposerScriptEvents::POST_UPDATE_CMD], true) + if (isset($scripts[ComposerScriptEvents::POST_INSTALL_CMD], $scripts[ComposerScriptEvents::POST_UPDATE_CMD]) + && \in_array($autoScript, $scripts[ComposerScriptEvents::POST_INSTALL_CMD], true) + && \in_array($autoScript, $scripts[ComposerScriptEvents::POST_UPDATE_CMD], true) ) { return; } - /** @var \Composer\Json\JsonFile $json */ - /** @var \Composer\Json\JsonManipulator $manipulator */ [$json, $manipulator] = Util::getComposerJsonFileAndManipulator(); if (\count($scripts) === 0) { @@ -361,8 +349,6 @@ public function onPostCreateProject(Event $event): void return; } - /** @var \Composer\Json\JsonFile $json */ - /** @var \Composer\Json\JsonManipulator $manipulator */ [$json, $manipulator] = Util::getComposerJsonFileAndManipulator(); // new projects are most of the time proprietary @@ -474,8 +460,6 @@ public function onPostUninstall(PackageEvent $event): void return; } - /** @var \Composer\Json\JsonFile $json */ - /** @var \Composer\Json\JsonManipulator $manipulator */ [$json, $manipulator] = Util::getComposerJsonFileAndManipulator(); foreach ((array) $scripts[ComposerScriptEvents::POST_INSTALL_CMD] as $key => $script) { @@ -708,7 +692,6 @@ public function executeAutoScripts(Event $event): void require_once $path; } - /** @var \Narrowspark\Automatic\Common\Contract\ScriptExtender $class */ $reflectionClass = new ReflectionClass($class); if ($reflectionClass->isInstantiable() && $reflectionClass->hasMethod('getType')) { @@ -784,7 +767,7 @@ public function whatProvides(Pool $pool, $name, $bypassFilters = false) $packages[] = [$job['packageName'], $job['constraint']]; } - $loadExtraRepos = !(new \ReflectionMethod(Pool::class, 'match'))->isPublic(); // Detect Composer < 1.7.3 + $loadExtraRepos = ! (new \ReflectionMethod(Pool::class, 'match'))->isPublic(); // Detect Composer < 1.7.3 $this->container->get(ParallelDownloader::class)->download($packages, static function ($packageName, $constraint) use (&$listed, &$packages, $pool, $loadExtraRepos): void { /** @var \Composer\Package\PackageInterface $package */ @@ -922,8 +905,6 @@ private function updateComposerLock(): void */ private function manipulateComposerJsonWithAllowAutoInstall(): void { - /** @var \Composer\Json\JsonFile $json */ - /** @var \Composer\Json\JsonManipulator $manipulator */ [$json, $manipulator] = Util::getComposerJsonFileAndManipulator(); $manipulator->addSubNode('extra', 'automatic.allow-auto-install', true); diff --git a/src/Security/SecurityPlugin.php b/src/Security/SecurityPlugin.php index 30f257c3..6bd699a0 100644 --- a/src/Security/SecurityPlugin.php +++ b/src/Security/SecurityPlugin.php @@ -21,21 +21,15 @@ use RecursiveDirectoryIterator; use RecursiveIteratorIterator; -class SecurityPlugin implements PluginInterface, EventSubscriberInterface, Capable +final class SecurityPlugin implements Capable, EventSubscriberInterface, PluginInterface { - /** - * @var string - */ + /** @var string */ public const VERSION = '0.12.0'; - /** - * @var string - */ + /** @var string */ public const COMPOSER_EXTRA_KEY = 'audit'; - /** - * @var string - */ + /** @var string */ public const PACKAGE_NAME = 'narrowspark/automatic-security-audit'; /** @@ -43,28 +37,28 @@ class SecurityPlugin implements PluginInterface, EventSubscriberInterface, Capab * * @var array */ - protected $securityAdvisories = []; + private $securityAdvisories = []; /** * Found package vulnerabilities. * * @var array[] */ - protected $foundVulnerabilities = []; + private $foundVulnerabilities = []; /** * The composer instance. * * @var \Composer\Composer */ - protected $composer; + private $composer; /** * The composer io implementation. * * @var \Composer\IO\IOInterface */ - protected $io; + private $io; /** * A Audit instance. @@ -115,7 +109,7 @@ public function activate(Composer $composer, IOInterface $io): void foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS)) as $file) { /** @var \SplFileInfo $file */ if (\substr($file->getFilename(), -4) === '.php') { - require_once $file; + class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__), -4))); } } From aaa21f9d3b63472c6beae1fde1168e1aaca8679f Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 22:08:36 +0200 Subject: [PATCH 02/10] style: fixed found cs errors on v2 narrowspark code style --- .php_cs | 2 ++ composer.json | 2 +- phpstan.neon | 15 +++++++++ .../ComposerScriptsConfigurator.php | 12 ++----- .../CopyFromPackageConfigurator.php | 1 + .../Exception/InvalidArgumentException.php | 2 +- .../Contract/PackageConfigurator.php | 4 +-- src/Automatic/Installer/AbstractInstaller.php | 8 ++--- src/Automatic/Installer/SkeletonInstaller.php | 2 +- src/Automatic/LegacyTagsManager.php | 6 ++-- src/Automatic/Operation/Install.php | 8 ++--- src/Automatic/Operation/Uninstall.php | 1 - src/Automatic/Prefetcher/Cache.php | 4 +-- .../Prefetcher/ComposerRepository.php | 6 ++-- .../Prefetcher/ParallelDownloader.php | 4 +-- src/Automatic/Prefetcher/Prefetcher.php | 17 ++++------ .../TruncatedComposerRepository.php | 2 +- src/Automatic/ScriptEvents.php | 2 +- src/Automatic/ScriptExecutor.php | 4 +-- src/Common/ClassFinder.php | 22 ++++++------- src/Common/Contract/Configurator.php | 4 +-- .../Exception/InvalidArgumentException.php | 2 +- .../Contract/Exception/RuntimeException.php | 2 +- .../Exception/UnexpectedValueException.php | 2 +- src/Common/Contract/Package.php | 18 +++++------ .../Installer/AbstractInstallationManager.php | 8 ++--- src/Common/Package.php | 29 ++++++++--------- .../ScriptExtender/PhpScriptExtender.php | 2 +- src/Security/Audit.php | 24 ++++++-------- src/Security/Command/AuditCommand.php | 14 ++++---- .../Command/Formatter/JsonFormatter.php | 2 +- .../Command/Formatter/SimpleFormatter.php | 2 +- .../Command/Formatter/TextFormatter.php | 2 +- .../Contract/Exception/RuntimeException.php | 2 +- .../Downloader/ComposerDownloader.php | 2 +- src/Security/Downloader/CurlDownloader.php | 2 +- src/Security/ScriptEvents.php | 2 +- tests/Automatic/AbstractConfiguratorTest.php | 12 ++----- tests/Automatic/AutomaticTest.php | 8 ++--- .../ComposerAutoScriptsConfiguratorTest.php | 20 +++--------- .../ComposerScriptsConfiguratorTest.php | 20 +++--------- .../CopyFromPackageConfiguratorTest.php | 12 ++----- .../Configurator/EnvConfiguratorTest.php | 20 +++--------- .../GitignoreConfiguratorTest.php | 16 +++------- tests/Automatic/ConfiguratorTest.php | 8 ++--- tests/Automatic/ContainerTest.php | 4 +-- .../Automatic/Fixture/ComposerJsonFactory.php | 2 +- .../prisis/install/Configurator.php | 2 +- .../Configurator/prisis/no/NoConfigurator.php | 2 +- .../prisis/update/UpdateConfigurator.php | 2 +- tests/Automatic/Fixture/MockConfigurator.php | 2 +- .../Automatic/TestExecutor.php | 2 +- .../Installer/AbstractInstallerTest.php | 32 +++++-------------- .../Installer/InstallationManagerTest.php | 8 ++--- tests/Automatic/LegacyTagsManagerTest.php | 12 ++----- tests/Automatic/LockTest.php | 4 +-- tests/Automatic/Operation/InstallTest.php | 13 ++------ .../Traits/ArrangeOperationsClasses.php | 28 ++++------------ tests/Automatic/Operation/UninstallTest.php | 8 ++--- .../Prefetcher/ParallelDownloaderTest.php | 4 +-- tests/Automatic/ScriptExecutorTest.php | 16 +++------- .../ScriptExtender/ScriptExtenderTest.php | 4 +-- tests/Automatic/SkeletonGeneratorTest.php | 18 +++-------- .../Traits/ArrangeComposerClasses.php | 24 ++++---------- tests/Common/Fixture/Finder/DummyClass.php | 2 +- tests/Common/Fixture/Finder/DummyClassTwo.php | 2 +- .../Finder/Nested/DummyClassNested.php | 2 +- .../Finder/StaticFunctionAndClasses.php | 2 +- tests/Common/PackageTest.php | 4 +-- tests/Common/PathTest.php | 32 +++++++++++++++++-- .../ScriptExtender/PhpScriptExtenderTest.php | 4 +-- .../Common/Traits/PhpFileMarkerTraitTest.php | 4 +-- tests/Security/AuditTest.php | 8 ++--- tests/Security/Command/AuditCommandTest.php | 12 ++----- .../Downloader/ComposerDownloaderTest.php | 8 ++--- .../Downloader/CurlDownloaderTest.php | 8 ++--- tests/Security/SecurityPluginTest.php | 8 ++--- 77 files changed, 237 insertions(+), 405 deletions(-) diff --git a/.php_cs b/.php_cs index 7f66d5b7..31a49fd0 100644 --- a/.php_cs +++ b/.php_cs @@ -8,6 +8,8 @@ $config = new Config(null, [ ], ], 'comment_to_phpdoc' => false, + 'final_class' => false, + 'PhpCsFixerCustomFixers/no_commented_out_code' => false, ]); $config->getFinder() ->files() diff --git a/composer.json b/composer.json index 4dbf1a40..b8d23fae 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "nyholm/nsa": "^1.1.0", "phpunit/phpunit": "^7.2.0", "ocramius/package-versions": "^1.4.0", - "narrowspark/coding-standard": "^1.4.0" + "narrowspark/coding-standard": "^2.0.0" }, "config": { "optimize-autoloader": true, diff --git a/phpstan.neon b/phpstan.neon index f780e79e..01b57e36 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -30,3 +30,18 @@ parameters: # Automatic - '#does not call parent constructor from Composer\\Repository\\ComposerRepository#' - '#Call to function method_exists\(\) with Symfony\\Component\\Console\\Style\\SymfonyStyle and#' + + # CopyFromPackageConfigurator + - '#Variable method call on Symfony\\Component\\Filesystem\\Filesystem#' + + # EnvConfigurator - phpstan missing support + - '#Strict comparison using \!== between bool and null will always evaluate to true#' + + # Package + - '#Variable method call on Narrowspark\\Automatic\\Common\\Package#' + + # PhpScriptExtender + - "#Casting to string something that's already string#" + + # GetGenericPropertyReaderTrait + - '#Variable property access on mixed#' diff --git a/src/Automatic/Configurator/ComposerScriptsConfigurator.php b/src/Automatic/Configurator/ComposerScriptsConfigurator.php index e06f32cf..0e866275 100644 --- a/src/Automatic/Configurator/ComposerScriptsConfigurator.php +++ b/src/Automatic/Configurator/ComposerScriptsConfigurator.php @@ -16,19 +16,13 @@ final class ComposerScriptsConfigurator extends AbstractConfigurator { - /** - * @var string - */ + /** @var string */ public const COMPOSER_EXTRA_KEY = 'composer-scripts'; - /** - * @var string - */ + /** @var string */ public const WHITELIST = 'whitelist'; - /** - * @var string - */ + /** @var string */ public const BLACKLIST = 'blacklist'; /** diff --git a/src/Automatic/Configurator/CopyFromPackageConfigurator.php b/src/Automatic/Configurator/CopyFromPackageConfigurator.php index ba24cae6..c1c7c659 100644 --- a/src/Automatic/Configurator/CopyFromPackageConfigurator.php +++ b/src/Automatic/Configurator/CopyFromPackageConfigurator.php @@ -43,6 +43,7 @@ public function configure(PackageContract $package): void } try { + /* @var string $functionName */ $functionName = 'copy'; if (\is_dir($from)) { diff --git a/src/Automatic/Contract/Exception/InvalidArgumentException.php b/src/Automatic/Contract/Exception/InvalidArgumentException.php index dea101f7..9837e79c 100644 --- a/src/Automatic/Contract/Exception/InvalidArgumentException.php +++ b/src/Automatic/Contract/Exception/InvalidArgumentException.php @@ -4,6 +4,6 @@ use InvalidArgumentException as BaseInvalidArgumentException; -class InvalidArgumentException extends BaseInvalidArgumentException implements Exception +final class InvalidArgumentException extends BaseInvalidArgumentException implements Exception { } diff --git a/src/Automatic/Contract/PackageConfigurator.php b/src/Automatic/Contract/PackageConfigurator.php index e2f391ca..3c59db52 100644 --- a/src/Automatic/Contract/PackageConfigurator.php +++ b/src/Automatic/Contract/PackageConfigurator.php @@ -4,8 +4,6 @@ interface PackageConfigurator extends Configurator { - /** - * @var string - */ + /** @var string */ public const TYPE = 'custom-configurators'; } diff --git a/src/Automatic/Installer/AbstractInstaller.php b/src/Automatic/Installer/AbstractInstaller.php index 7bd857bb..f788102b 100644 --- a/src/Automatic/Installer/AbstractInstaller.php +++ b/src/Automatic/Installer/AbstractInstaller.php @@ -14,14 +14,10 @@ abstract class AbstractInstaller extends LibraryInstaller { - /** - * @var string - */ + /** @var string */ public const TYPE = null; - /** - * @var string - */ + /** @var string */ public const LOCK_KEY = null; /** diff --git a/src/Automatic/Installer/SkeletonInstaller.php b/src/Automatic/Installer/SkeletonInstaller.php index 42c14dbd..f9478703 100644 --- a/src/Automatic/Installer/SkeletonInstaller.php +++ b/src/Automatic/Installer/SkeletonInstaller.php @@ -4,7 +4,7 @@ use Composer\Package\PackageInterface; -class SkeletonInstaller extends AbstractInstaller +final class SkeletonInstaller extends AbstractInstaller { /** * {@inheritdoc} diff --git a/src/Automatic/LegacyTagsManager.php b/src/Automatic/LegacyTagsManager.php index c8e2799c..f50ce644 100644 --- a/src/Automatic/LegacyTagsManager.php +++ b/src/Automatic/LegacyTagsManager.php @@ -30,9 +30,7 @@ final class LegacyTagsManager implements Resettable */ private $legacyTags = []; - /** - * @var array - */ + /** @var array */ private static $packageCache = []; /** @@ -108,7 +106,7 @@ public function removeLegacyTags(array $data): array foreach ($data['packages'][$name] as $version => $composerJson) { if ($version === 'dev-master' && null !== $devMasterVersion = $composerJson['extra']['branch-alias']['dev-master'] ?? null) { $normalizedVersion = $this->versionParser->normalize($devMasterVersion); - } elseif (!isset($composerJson['version_normalized'])) { + } elseif (! isset($composerJson['version_normalized'])) { continue; } else { $normalizedVersion = $composerJson['version_normalized']; diff --git a/src/Automatic/Operation/Install.php b/src/Automatic/Operation/Install.php index 146fbe9b..1d979b18 100644 --- a/src/Automatic/Operation/Install.php +++ b/src/Automatic/Operation/Install.php @@ -30,8 +30,8 @@ public function supports(OperationInterface $operation): bool $composerPackage = $operation->getPackage(); } - return ($operation instanceof UpdateOperation || $operation instanceof InstallOperation) && - (\file_exists($this->getAutomaticFilePath($composerPackage)) || isset($composerPackage->getExtra()['automatic'])); + return ($operation instanceof UpdateOperation || $operation instanceof InstallOperation) + && (\file_exists($this->getAutomaticFilePath($composerPackage)) || isset($composerPackage->getExtra()['automatic'])); } /** @@ -103,8 +103,8 @@ private function getPackageVersion(PackageInterface $package): string $branchAliases = $extra['branch-alias']; if ( - (isset($branchAliases[$version]) && $alias = $branchAliases[$version]) || - (isset($branchAliases['dev-master']) && $alias = $branchAliases['dev-master']) + (isset($branchAliases[$version]) && $alias = $branchAliases[$version]) + || (isset($branchAliases['dev-master']) && $alias = $branchAliases['dev-master']) ) { $version = $alias; } diff --git a/src/Automatic/Operation/Uninstall.php b/src/Automatic/Operation/Uninstall.php index b2ce457b..80e604f5 100644 --- a/src/Automatic/Operation/Uninstall.php +++ b/src/Automatic/Operation/Uninstall.php @@ -27,7 +27,6 @@ public function supports(OperationInterface $operation): bool */ public function resolve(OperationInterface $operation): PackageContract { - /** @var \Composer\DependencyResolver\Operation\UninstallOperation $operation */ $name = $operation->getPackage()->getName(); $package = Package::createFromLock($name, (array) $this->lock->get(Automatic::LOCK_PACKAGES, $name)); diff --git a/src/Automatic/Prefetcher/Cache.php b/src/Automatic/Prefetcher/Cache.php index f3e3d3a9..bc8de239 100644 --- a/src/Automatic/Prefetcher/Cache.php +++ b/src/Automatic/Prefetcher/Cache.php @@ -12,7 +12,7 @@ * * (c) Nicolas Grekas */ -class Cache extends BaseComposerCache +final class Cache extends BaseComposerCache { /** * A tags manager instance. @@ -34,7 +34,7 @@ public function setTagsManager(LegacyTagsManager $tagsManager): void } /** - * @param string $file + * @param mixed $file * * @return bool|string */ diff --git a/src/Automatic/Prefetcher/ComposerRepository.php b/src/Automatic/Prefetcher/ComposerRepository.php index 831c8e4c..64e42d21 100644 --- a/src/Automatic/Prefetcher/ComposerRepository.php +++ b/src/Automatic/Prefetcher/ComposerRepository.php @@ -11,11 +11,9 @@ * * (c) Nicolas Grekas */ -class ComposerRepository extends BaseComposerRepository +final class ComposerRepository extends BaseComposerRepository { - /** - * @var null|array - */ + /** @var null|array */ private $providerFiles; /** diff --git a/src/Automatic/Prefetcher/ParallelDownloader.php b/src/Automatic/Prefetcher/ParallelDownloader.php index 4669cfba..54ce4203 100644 --- a/src/Automatic/Prefetcher/ParallelDownloader.php +++ b/src/Automatic/Prefetcher/ParallelDownloader.php @@ -58,9 +58,7 @@ class ParallelDownloader extends RemoteFilesystem */ private $progress = true; - /** - * @var null|callable - */ + /** @var null|callable */ private $nextCallback; /** diff --git a/src/Automatic/Prefetcher/Prefetcher.php b/src/Automatic/Prefetcher/Prefetcher.php index 8c345593..eea8afcd 100644 --- a/src/Automatic/Prefetcher/Prefetcher.php +++ b/src/Automatic/Prefetcher/Prefetcher.php @@ -79,9 +79,7 @@ class Prefetcher */ private $cacheDirPopulated = false; - /** - * @var array - */ + /** @var array */ private static $repoReadingCommands = [ 'create-project' => true, 'outdated' => true, @@ -137,17 +135,15 @@ public function populateRepoCacheDir(): void } /** - * @param \Composer\Util\RemoteFilesystem $remoteFilesystem - * * @return void */ public function prefetchComposerRepositories(): void { $command = $this->input->getFirstArgument(); - if ($this->populateRepoCacheDir === true && - isset(self::$repoReadingCommands[$command]) && - ($command !== 'install' || (\file_exists(Factory::getComposerFile()) && ! \file_exists(Util::getComposerLockFile()))) + if ($this->populateRepoCacheDir === true + && isset(self::$repoReadingCommands[$command]) + && ($command !== 'install' || (\file_exists(Factory::getComposerFile()) && ! \file_exists(Util::getComposerLockFile()))) ) { $repos = []; @@ -188,7 +184,6 @@ public function fetchAllFromOperations($event): void $downloads = []; foreach ($event->getOperations() as $i => $operation) { - /** @var \Composer\Package\PackageInterface $package */ switch ($operation->getJobType()) { case 'install': $package = $operation->getPackage(); @@ -219,8 +214,8 @@ public function fetchAllFromOperations($event): void continue; } - if (\preg_match('#^https://github\.com/#', $package->getSourceUrl()) && - \preg_match('#^https://api\.github\.com/repos(/[^/]++/[^/]++/)zipball(.++)$#', $url, $matches) + if (\preg_match('#^https://github\.com/#', $package->getSourceUrl()) + && \preg_match('#^https://api\.github\.com/repos(/[^/]++/[^/]++/)zipball(.++)$#', $url, $matches) ) { $url = \sprintf('https://codeload.github.com%slegacy.zip%s', $matches[1], $matches[2]); } diff --git a/src/Automatic/Prefetcher/TruncatedComposerRepository.php b/src/Automatic/Prefetcher/TruncatedComposerRepository.php index eb0999ec..777c20f4 100644 --- a/src/Automatic/Prefetcher/TruncatedComposerRepository.php +++ b/src/Automatic/Prefetcher/TruncatedComposerRepository.php @@ -16,7 +16,7 @@ * * (c) Nicolas Grekas */ -class TruncatedComposerRepository extends BaseComposerRepository +final class TruncatedComposerRepository extends BaseComposerRepository { /** * {@inheritdoc} diff --git a/src/Automatic/ScriptEvents.php b/src/Automatic/ScriptEvents.php index 2b5895d8..ee878d1a 100644 --- a/src/Automatic/ScriptEvents.php +++ b/src/Automatic/ScriptEvents.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Narrowspark\Automatic; -class ScriptEvents +final class ScriptEvents { /** * The AUTO_SCRIPTS event occurs after a package is installed or updated. diff --git a/src/Automatic/ScriptExecutor.php b/src/Automatic/ScriptExecutor.php index 0f91ea5f..4447931b 100644 --- a/src/Automatic/ScriptExecutor.php +++ b/src/Automatic/ScriptExecutor.php @@ -16,9 +16,7 @@ final class ScriptExecutor { use ExpandTargetDirTrait; - /** - * @var string - */ + /** @var string */ public const TYPE = 'script-extenders'; /** diff --git a/src/Common/ClassFinder.php b/src/Common/ClassFinder.php index d4cbf17a..a20a3fa7 100644 --- a/src/Common/ClassFinder.php +++ b/src/Common/ClassFinder.php @@ -46,7 +46,7 @@ final class ClassFinder implements ResettableContract /** * All given paths for psr4 and prs0. * - * @var array[]|string[] + * @var array */ private $paths; @@ -124,7 +124,7 @@ public function getClasses(): array * * @param array $excludes * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function setExcludes(array $excludes): self { @@ -140,7 +140,7 @@ public function setExcludes(array $excludes): self * * @param \Closure $filter * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function setFilter(Closure $filter): self { @@ -155,7 +155,7 @@ public function setFilter(Closure $filter): self * @param string $packageName * @param array $autoload * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function setComposerAutoload(string $packageName, array $autoload): self { @@ -186,7 +186,7 @@ public function setComposerAutoload(string $packageName, array $autoload): self * @param string $packageName * @param array $paths * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function addPsr0(string $packageName, array $paths): self { @@ -201,7 +201,7 @@ public function addPsr0(string $packageName, array $paths): self * @param string $packageName * @param array $paths * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function addPsr4(string $packageName, array $paths): self { @@ -216,7 +216,7 @@ public function addPsr4(string $packageName, array $paths): self * @param string $packageName * @param array $paths * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function addClassmap(string $packageName, array $paths): self { @@ -228,15 +228,15 @@ public function addClassmap(string $packageName, array $paths): self /** * Find all the class, traits and interface names in a given directory. * - * @return \Narrowspark\Automatic\Common\ClassFinder + * @return self */ public function find(): self { $preparedPaths = \array_unique( \array_merge( - $this->getPreparedPaths((array) $this->paths['psr0']), - $this->getPreparedPaths((array) $this->paths['psr4']), - $this->getPreparedPaths((array) $this->paths['classmap']) + $this->getPreparedPaths($this->paths['psr0']), + $this->getPreparedPaths($this->paths['psr4']), + $this->getPreparedPaths($this->paths['classmap']) ), \SORT_STRING ); diff --git a/src/Common/Contract/Configurator.php b/src/Common/Contract/Configurator.php index 289dd8ec..89b4b705 100644 --- a/src/Common/Contract/Configurator.php +++ b/src/Common/Contract/Configurator.php @@ -4,9 +4,7 @@ interface Configurator { - /** - * @var string - */ + /** @var string */ public const TYPE = 'configurators'; /** diff --git a/src/Common/Contract/Exception/InvalidArgumentException.php b/src/Common/Contract/Exception/InvalidArgumentException.php index c5b063dc..1b1ec963 100644 --- a/src/Common/Contract/Exception/InvalidArgumentException.php +++ b/src/Common/Contract/Exception/InvalidArgumentException.php @@ -4,6 +4,6 @@ use InvalidArgumentException as BaseInvalidArgumentException; -class InvalidArgumentException extends BaseInvalidArgumentException implements Exception +final class InvalidArgumentException extends BaseInvalidArgumentException implements Exception { } diff --git a/src/Common/Contract/Exception/RuntimeException.php b/src/Common/Contract/Exception/RuntimeException.php index 5659b11f..350db021 100644 --- a/src/Common/Contract/Exception/RuntimeException.php +++ b/src/Common/Contract/Exception/RuntimeException.php @@ -4,6 +4,6 @@ use RuntimeException as BaseRuntimeException; -class RuntimeException extends BaseRuntimeException implements Exception +final class RuntimeException extends BaseRuntimeException implements Exception { } diff --git a/src/Common/Contract/Exception/UnexpectedValueException.php b/src/Common/Contract/Exception/UnexpectedValueException.php index d32ed41b..ffc78753 100644 --- a/src/Common/Contract/Exception/UnexpectedValueException.php +++ b/src/Common/Contract/Exception/UnexpectedValueException.php @@ -4,6 +4,6 @@ use UnexpectedValueException as BaseUnexpectedValueException; -class UnexpectedValueException extends BaseUnexpectedValueException implements Exception +final class UnexpectedValueException extends BaseUnexpectedValueException implements Exception { } diff --git a/src/Common/Contract/Package.php b/src/Common/Contract/Package.php index e83ee2d2..614d8354 100644 --- a/src/Common/Contract/Package.php +++ b/src/Common/Contract/Package.php @@ -15,7 +15,7 @@ interface Package * * @param string $name * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setName(string $name): self; @@ -45,7 +45,7 @@ public function getPrettyVersion(): ?string; * * @param bool $bool * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setIsDev(bool $bool = true): self; @@ -61,7 +61,7 @@ public function isDev(): bool; * * @param array $autoload * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setAutoload(array $autoload): self; @@ -77,7 +77,7 @@ public function getAutoload(): array; * * @param string $url * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setUrl(string $url): self; @@ -109,7 +109,7 @@ public function getType(): ?string; * * @param string $operation * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setOperation(string $operation): self; @@ -125,7 +125,7 @@ public function getOperation(): ?string; * * @param string[] $requires * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setRequires(array $requires): self; @@ -141,7 +141,7 @@ public function getRequires(): array; * * @param array $configs * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setConfig(array $configs): self; @@ -177,7 +177,7 @@ public function getConfigs(): array; * * @param string $name * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setParentName(string $name): self; @@ -193,7 +193,7 @@ public function getParentName(): ?string; * * @param string $time this \DateTime::RFC3339 format should be used * - * @return \Narrowspark\Automatic\Common\Contract\Package + * @return self */ public function setTime(string $time): self; diff --git a/src/Common/Installer/AbstractInstallationManager.php b/src/Common/Installer/AbstractInstallationManager.php index eea110ed..c644766c 100644 --- a/src/Common/Installer/AbstractInstallationManager.php +++ b/src/Common/Installer/AbstractInstallationManager.php @@ -24,14 +24,10 @@ abstract class AbstractInstallationManager { use GetGenericPropertyReaderTrait; - /** - * @var int - */ + /** @var int */ protected const ADD = 1; - /** - * @var int - */ + /** @var int */ protected const REMOVE = 0; /** diff --git a/src/Common/Package.php b/src/Common/Package.php index 86713874..94c713c1 100644 --- a/src/Common/Package.php +++ b/src/Common/Package.php @@ -296,7 +296,7 @@ public static function createFromLock(string $name, array $packageData): Package 'created' => 'setTime', ]; - $package = new static($name, $packageData['version']); + $package = new self($name, $packageData['version']); foreach ($packageData as $key => $data) { if ($data !== null && isset($keyToFunctionMappers[$key])) { @@ -376,19 +376,18 @@ public function getTime(): string */ public function toArray(): array { - return - [ - 'pretty-name' => $this->prettyName, - 'version' => $this->prettyVersion, - 'parent' => $this->parentName, - 'is-dev' => $this->isDev, - 'url' => $this->url, - 'operation' => $this->operation, - 'type' => $this->type, - 'requires' => $this->requires, - 'automatic-extra' => $this->configs, - 'autoload' => $this->autoload, - 'created' => $this->created, - ]; + return [ + 'pretty-name' => $this->prettyName, + 'version' => $this->prettyVersion, + 'parent' => $this->parentName, + 'is-dev' => $this->isDev, + 'url' => $this->url, + 'operation' => $this->operation, + 'type' => $this->type, + 'requires' => $this->requires, + 'automatic-extra' => $this->configs, + 'autoload' => $this->autoload, + 'created' => $this->created, + ]; } } diff --git a/src/Common/ScriptExtender/PhpScriptExtender.php b/src/Common/ScriptExtender/PhpScriptExtender.php index dcf13261..2eeae3cb 100644 --- a/src/Common/ScriptExtender/PhpScriptExtender.php +++ b/src/Common/ScriptExtender/PhpScriptExtender.php @@ -6,7 +6,7 @@ use Narrowspark\Automatic\Common\Contract\Exception\RuntimeException; use Symfony\Component\Process\PhpExecutableFinder; -class PhpScriptExtender extends AbstractScriptExtender +final class PhpScriptExtender extends AbstractScriptExtender { /** * {@inheritdoc} diff --git a/src/Security/Audit.php b/src/Security/Audit.php index ac778f21..f297c77e 100644 --- a/src/Security/Audit.php +++ b/src/Security/Audit.php @@ -11,21 +11,15 @@ use Narrowspark\Automatic\Security\Contract\Exception\RuntimeException; use Symfony\Component\Filesystem\Filesystem; -class Audit +final class Audit { - /** - * @var string - */ + /** @var string */ private const SECURITY_ADVISORIES_BASE_URL = 'https://raw.githubusercontent.com/narrowspark/security-advisories/master/'; - /** - * @var string - */ + /** @var string */ private const SECURITY_ADVISORIES_SHA = 'security-advisories-sha'; - /** - * @var string - */ + /** @var string */ private const SECURITY_ADVISORIES = 'security-advisories.json'; /** @@ -33,7 +27,7 @@ class Audit * * @var \Symfony\Component\Filesystem\Filesystem */ - protected $filesystem; + private $filesystem; /** * A version parser instance. @@ -236,11 +230,11 @@ private function checkPackageAgainstSecurityAdvisories( continue; } - foreach ($advisoryData['branches'] as $name => $branch) { + foreach ($advisoryData['branches'] as $n => $branch) { if (! isset($branch['versions'])) { - $messages[$name][] = \sprintf('Key [versions] is not set for branch [%s].', $key); + $messages[$n][] = \sprintf('Key [versions] is not set for branch [%s].', $key); } elseif (! \is_array($branch['versions'])) { - $messages[$name][] = \sprintf('Key [versions] is expected to be an array for branch [%s].', $key); + $messages[$n][] = \sprintf('Key [versions] is expected to be an array for branch [%s].', $key); } else { $constraints = []; @@ -256,7 +250,7 @@ private function checkPackageAgainstSecurityAdvisories( } if (null === $op) { - $messages[$name][] = \sprintf('Version [%s] does not contain a supported operator.', $version); + $messages[$n][] = \sprintf('Version [%s] does not contain a supported operator.', $version); continue; } diff --git a/src/Security/Command/AuditCommand.php b/src/Security/Command/AuditCommand.php index b4bb14a0..8eeb21d2 100644 --- a/src/Security/Command/AuditCommand.php +++ b/src/Security/Command/AuditCommand.php @@ -18,11 +18,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class AuditCommand extends BaseCommand +final class AuditCommand extends BaseCommand { - /** - * @var string - */ + /** @var string */ protected static $defaultName = 'audit'; /** @@ -105,8 +103,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (\count($messages) !== 0) { $output->note('Please report this found messages to https://github.com/narrowspark/security-advisories.'); - foreach ($messages as $key => $message) { - $output->writeln($key . ': ' . $message); + foreach ($messages as $key => $msg) { + $output->writeln($key . ': ' . $msg); } } @@ -129,8 +127,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $formatter->displayResults($output, $vulnerabilities); - $output->writeln('[!] ' . \sprintf('%s vulnerabilit%s found - ', $count, $count === 1 ? 'y' : 'ies') . - 'We recommend you to check the related security advisories and upgrade these dependencies.'); + $output->writeln('[!] ' . \sprintf('%s vulnerabilit%s found - ', $count, $count === 1 ? 'y' : 'ies') + . 'We recommend you to check the related security advisories and upgrade these dependencies.'); return $errorExitCode; } diff --git a/src/Security/Command/Formatter/JsonFormatter.php b/src/Security/Command/Formatter/JsonFormatter.php index 7e835ebe..91b127ee 100644 --- a/src/Security/Command/Formatter/JsonFormatter.php +++ b/src/Security/Command/Formatter/JsonFormatter.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Security\Contract\Command\Formatter as FormatterContract; use Symfony\Component\Console\Style\SymfonyStyle; -class JsonFormatter implements FormatterContract +final class JsonFormatter implements FormatterContract { /** * {@inheritdoc} diff --git a/src/Security/Command/Formatter/SimpleFormatter.php b/src/Security/Command/Formatter/SimpleFormatter.php index 4ab96020..e939b3d7 100644 --- a/src/Security/Command/Formatter/SimpleFormatter.php +++ b/src/Security/Command/Formatter/SimpleFormatter.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Security\Contract\Command\Formatter as FormatterContract; use Symfony\Component\Console\Style\SymfonyStyle; -class SimpleFormatter implements FormatterContract +final class SimpleFormatter implements FormatterContract { /** * {@inheritdoc} diff --git a/src/Security/Command/Formatter/TextFormatter.php b/src/Security/Command/Formatter/TextFormatter.php index e7eeed83..7d6c0023 100644 --- a/src/Security/Command/Formatter/TextFormatter.php +++ b/src/Security/Command/Formatter/TextFormatter.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Security\Contract\Command\Formatter as FormatterContract; use Symfony\Component\Console\Style\SymfonyStyle; -class TextFormatter implements FormatterContract +final class TextFormatter implements FormatterContract { /** * {@inheritdoc} diff --git a/src/Security/Contract/Exception/RuntimeException.php b/src/Security/Contract/Exception/RuntimeException.php index 9532af55..4a6239c7 100644 --- a/src/Security/Contract/Exception/RuntimeException.php +++ b/src/Security/Contract/Exception/RuntimeException.php @@ -4,6 +4,6 @@ use RuntimeException as BaseRuntimeException; -class RuntimeException extends BaseRuntimeException implements Exception +final class RuntimeException extends BaseRuntimeException implements Exception { } diff --git a/src/Security/Downloader/ComposerDownloader.php b/src/Security/Downloader/ComposerDownloader.php index 4b5252ea..af97ac8f 100644 --- a/src/Security/Downloader/ComposerDownloader.php +++ b/src/Security/Downloader/ComposerDownloader.php @@ -6,7 +6,7 @@ use Composer\Util\StreamContextFactory; use Narrowspark\Automatic\Security\Contract\Exception\RuntimeException; -class ComposerDownloader extends AbstractDownloader +final class ComposerDownloader extends AbstractDownloader { /** * {@inheritdoc} diff --git a/src/Security/Downloader/CurlDownloader.php b/src/Security/Downloader/CurlDownloader.php index ef98a259..3847b90f 100644 --- a/src/Security/Downloader/CurlDownloader.php +++ b/src/Security/Downloader/CurlDownloader.php @@ -5,7 +5,7 @@ use Composer\CaBundle\CaBundle; use Narrowspark\Automatic\Security\Contract\Exception\RuntimeException; -class CurlDownloader extends AbstractDownloader +final class CurlDownloader extends AbstractDownloader { /** * {@inheritdoc} diff --git a/src/Security/ScriptEvents.php b/src/Security/ScriptEvents.php index 2576a391..592774f0 100644 --- a/src/Security/ScriptEvents.php +++ b/src/Security/ScriptEvents.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Narrowspark\Automatic\Security; -class ScriptEvents +final class ScriptEvents { /** * The POST_MESSAGES event occurs after a package is installed or updated. diff --git a/tests/Automatic/AbstractConfiguratorTest.php b/tests/Automatic/AbstractConfiguratorTest.php index 7d71f201..2954fd97 100644 --- a/tests/Automatic/AbstractConfiguratorTest.php +++ b/tests/Automatic/AbstractConfiguratorTest.php @@ -13,19 +13,13 @@ */ abstract class AbstractConfiguratorTest extends MockeryTestCase { - /** - * @var \Composer\Composer|\Mockery\MockInterface - */ + /** @var \Composer\Composer|\Mockery\MockInterface */ protected $composerMock; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ protected $ioMock; - /** - * @var \Narrowspark\Automatic\Configurator - */ + /** @var \Narrowspark\Automatic\Configurator */ protected $configurator; /** diff --git a/tests/Automatic/AutomaticTest.php b/tests/Automatic/AutomaticTest.php index 4d63cdd6..3633f9ef 100644 --- a/tests/Automatic/AutomaticTest.php +++ b/tests/Automatic/AutomaticTest.php @@ -49,9 +49,7 @@ final class AutomaticTest extends MockeryTestCase { use ArrangeComposerClasses; - /** - * @var \Narrowspark\Automatic\Automatic - */ + /** @var \Narrowspark\Automatic\Automatic */ private $automatic; /** @@ -710,7 +708,7 @@ public function testInitAutoScripts(): void $lockContent = \json_decode(\file_get_contents($composerLockPath), true); - $this->assertInternalType('string', $lockContent['content-hash']); + $this->assertIsString($lockContent['content-hash']); \putenv('COMPOSER='); \putenv('COMPOSER'); @@ -783,7 +781,7 @@ public function testOnPostCreateProject(): void $lockContent = \json_decode(\file_get_contents($composerLockPath), true); - $this->assertInternalType('string', $lockContent['content-hash']); + $this->assertIsString($lockContent['content-hash']); \putenv('COMPOSER='); \putenv('COMPOSER'); diff --git a/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php b/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php index 8aa1d708..b098dfa0 100644 --- a/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php +++ b/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php @@ -20,29 +20,19 @@ final class ComposerAutoScriptsConfiguratorTest extends MockeryTestCase { use GetGenericPropertyReaderTrait; - /** - * @var \Composer\Composer - */ + /** @var \Composer\Composer */ private $composer; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ private $ioMock; - /** - * @var \Composer\Json\JsonFile|\Mockery\MockInterface - */ + /** @var \Composer\Json\JsonFile|\Mockery\MockInterface */ private $jsonMock; - /** - * @var \Composer\Json\JsonManipulator|\Mockery\MockInterface - */ + /** @var \Composer\Json\JsonManipulator|\Mockery\MockInterface */ private $jsonManipulatorMock; - /** - * @var \Narrowspark\Automatic\Configurator\ComposerAutoScriptsConfigurator - */ + /** @var \Narrowspark\Automatic\Configurator\ComposerAutoScriptsConfigurator */ private $configurator; /** diff --git a/tests/Automatic/Configurator/ComposerScriptsConfiguratorTest.php b/tests/Automatic/Configurator/ComposerScriptsConfiguratorTest.php index 151b17c9..3c1a2d4c 100644 --- a/tests/Automatic/Configurator/ComposerScriptsConfiguratorTest.php +++ b/tests/Automatic/Configurator/ComposerScriptsConfiguratorTest.php @@ -22,29 +22,19 @@ final class ComposerScriptsConfiguratorTest extends MockeryTestCase { use GetGenericPropertyReaderTrait; - /** - * @var \Composer\Composer - */ + /** @var \Composer\Composer */ private $composer; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ private $ioMock; - /** - * @var \Composer\Json\JsonFile|\Mockery\MockInterface - */ + /** @var \Composer\Json\JsonFile|\Mockery\MockInterface */ private $jsonMock; - /** - * @var \Composer\Json\JsonManipulator|\Mockery\MockInterface - */ + /** @var \Composer\Json\JsonManipulator|\Mockery\MockInterface */ private $jsonManipulatorMock; - /** - * @var \Narrowspark\Automatic\Configurator\ComposerScriptsConfigurator - */ + /** @var \Narrowspark\Automatic\Configurator\ComposerScriptsConfigurator */ private $configurator; /** diff --git a/tests/Automatic/Configurator/CopyFromPackageConfiguratorTest.php b/tests/Automatic/Configurator/CopyFromPackageConfiguratorTest.php index 7e0a8d9f..2ea18ddf 100644 --- a/tests/Automatic/Configurator/CopyFromPackageConfiguratorTest.php +++ b/tests/Automatic/Configurator/CopyFromPackageConfiguratorTest.php @@ -16,19 +16,13 @@ */ final class CopyFromPackageConfiguratorTest extends MockeryTestCase { - /** - * @var \Composer\Composer|\Mockery\MockInterface - */ + /** @var \Composer\Composer|\Mockery\MockInterface */ private $composerMock; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ private $ioMock; - /** - * @var \Narrowspark\Automatic\Configurator\CopyFromPackageConfigurator - */ + /** @var \Narrowspark\Automatic\Configurator\CopyFromPackageConfigurator */ private $configurator; /** diff --git a/tests/Automatic/Configurator/EnvConfiguratorTest.php b/tests/Automatic/Configurator/EnvConfiguratorTest.php index 67a70d94..a1249119 100644 --- a/tests/Automatic/Configurator/EnvConfiguratorTest.php +++ b/tests/Automatic/Configurator/EnvConfiguratorTest.php @@ -14,29 +14,19 @@ */ final class EnvConfiguratorTest extends MockeryTestCase { - /** - * @var \Composer\Composer - */ + /** @var \Composer\Composer */ private $composer; - /** - * @var \Composer\IO\NullIo - */ + /** @var \Composer\IO\NullIo */ private $nullIo; - /** - * @var \Narrowspark\Automatic\Configurator\EnvConfigurator - */ + /** @var \Narrowspark\Automatic\Configurator\EnvConfigurator */ private $configurator; - /** - * @var string - */ + /** @var string */ private $envDistPath; - /** - * @var string - */ + /** @var string */ private $envPath; /** diff --git a/tests/Automatic/Configurator/GitignoreConfiguratorTest.php b/tests/Automatic/Configurator/GitignoreConfiguratorTest.php index 23146565..bb23ebe3 100644 --- a/tests/Automatic/Configurator/GitignoreConfiguratorTest.php +++ b/tests/Automatic/Configurator/GitignoreConfiguratorTest.php @@ -14,24 +14,16 @@ */ final class GitignoreConfiguratorTest extends TestCase { - /** - * @var \Composer\Composer - */ + /** @var \Composer\Composer */ private $composer; - /** - * @var \Composer\IO\NullIo - */ + /** @var \Composer\IO\NullIo */ private $nullIo; - /** - * @var \Narrowspark\Automatic\Configurator\GitignoreConfigurator - */ + /** @var \Narrowspark\Automatic\Configurator\GitignoreConfigurator */ private $configurator; - /** - * @var string - */ + /** @var string */ private $gitignorePath; /** diff --git a/tests/Automatic/ConfiguratorTest.php b/tests/Automatic/ConfiguratorTest.php index 70f1dcbd..7ae8f977 100644 --- a/tests/Automatic/ConfiguratorTest.php +++ b/tests/Automatic/ConfiguratorTest.php @@ -12,14 +12,10 @@ */ final class ConfiguratorTest extends AbstractConfiguratorTest { - /** - * @var string - */ + /** @var string */ private $copyFileName; - /** - * @var string - */ + /** @var string */ private $copyPath; /** diff --git a/tests/Automatic/ContainerTest.php b/tests/Automatic/ContainerTest.php index 0722692f..75ff874c 100644 --- a/tests/Automatic/ContainerTest.php +++ b/tests/Automatic/ContainerTest.php @@ -34,9 +34,7 @@ */ final class ContainerTest extends MockeryTestCase { - /** - * @var \Narrowspark\Automatic\Container - */ + /** @var \Narrowspark\Automatic\Container */ private static $staticContainer; /** diff --git a/tests/Automatic/Fixture/ComposerJsonFactory.php b/tests/Automatic/Fixture/ComposerJsonFactory.php index a3363d5e..144c96bd 100644 --- a/tests/Automatic/Fixture/ComposerJsonFactory.php +++ b/tests/Automatic/Fixture/ComposerJsonFactory.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Narrowspark\Automatic\Test\Fixture; -class ComposerJsonFactory +final class ComposerJsonFactory { /** * @param string $name diff --git a/tests/Automatic/Fixture/Configurator/prisis/install/Configurator.php b/tests/Automatic/Fixture/Configurator/prisis/install/Configurator.php index 490168d6..ce78fe22 100644 --- a/tests/Automatic/Fixture/Configurator/prisis/install/Configurator.php +++ b/tests/Automatic/Fixture/Configurator/prisis/install/Configurator.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; -class Configurator implements ConfiguratorContract +final class Configurator implements ConfiguratorContract { /** * {@inheritdoc} diff --git a/tests/Automatic/Fixture/Configurator/prisis/no/NoConfigurator.php b/tests/Automatic/Fixture/Configurator/prisis/no/NoConfigurator.php index d0ea109c..fae07c0e 100644 --- a/tests/Automatic/Fixture/Configurator/prisis/no/NoConfigurator.php +++ b/tests/Automatic/Fixture/Configurator/prisis/no/NoConfigurator.php @@ -2,6 +2,6 @@ declare(strict_types=1); namespace Test; -class NoConfigurator +final class NoConfigurator { } diff --git a/tests/Automatic/Fixture/Configurator/prisis/update/UpdateConfigurator.php b/tests/Automatic/Fixture/Configurator/prisis/update/UpdateConfigurator.php index 1e6f7422..8d251d50 100644 --- a/tests/Automatic/Fixture/Configurator/prisis/update/UpdateConfigurator.php +++ b/tests/Automatic/Fixture/Configurator/prisis/update/UpdateConfigurator.php @@ -4,7 +4,7 @@ use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; -class UpdateConfigurator implements ConfiguratorContract +final class UpdateConfigurator implements ConfiguratorContract { /** * {@inheritdoc} diff --git a/tests/Automatic/Fixture/MockConfigurator.php b/tests/Automatic/Fixture/MockConfigurator.php index b34c0df4..c2c105db 100644 --- a/tests/Automatic/Fixture/MockConfigurator.php +++ b/tests/Automatic/Fixture/MockConfigurator.php @@ -6,7 +6,7 @@ use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; -class MockConfigurator extends AbstractConfigurator +final class MockConfigurator extends AbstractConfigurator { public static function getName(): string { diff --git a/tests/Automatic/Fixture/Test/TransformWithScriptsExecutor/Automatic/TestExecutor.php b/tests/Automatic/Fixture/Test/TransformWithScriptsExecutor/Automatic/TestExecutor.php index 40a05fa4..ddbd76ce 100644 --- a/tests/Automatic/Fixture/Test/TransformWithScriptsExecutor/Automatic/TestExecutor.php +++ b/tests/Automatic/Fixture/Test/TransformWithScriptsExecutor/Automatic/TestExecutor.php @@ -4,7 +4,7 @@ use Narrowspark\Automatic\Common\ScriptExtender\AbstractScriptExtender; -class TestExecutor extends AbstractScriptExtender +final class TestExecutor extends AbstractScriptExtender { public static function getType(): string { diff --git a/tests/Automatic/Installer/AbstractInstallerTest.php b/tests/Automatic/Installer/AbstractInstallerTest.php index c5a617a1..5f019715 100644 --- a/tests/Automatic/Installer/AbstractInstallerTest.php +++ b/tests/Automatic/Installer/AbstractInstallerTest.php @@ -19,44 +19,28 @@ abstract class AbstractInstallerTest extends MockeryTestCase { use ArrangeComposerClasses; - /** - * @var \Composer\Repository\InstalledRepositoryInterface|\Mockery\MockInterface - */ + /** @var \Composer\Repository\InstalledRepositoryInterface|\Mockery\MockInterface */ protected $repositoryMock; - /** - * @var \Composer\Package\PackageInterface|\Mockery\MockInterface - */ + /** @var \Composer\Package\PackageInterface|\Mockery\MockInterface */ protected $packageMock; - /** - * @var \Composer\Package\PackageInterface|\Mockery\MockInterface - */ + /** @var \Composer\Package\PackageInterface|\Mockery\MockInterface */ protected $targetPackageMock; - /** - * @var \Narrowspark\Automatic\Installer\AbstractInstaller - */ + /** @var \Narrowspark\Automatic\Installer\AbstractInstaller */ protected $configuratorInstaller; - /** - * @var \Composer\Downloader\DownloadManager|\Mockery\MockInterface - */ + /** @var \Composer\Downloader\DownloadManager|\Mockery\MockInterface */ protected $downloadManagerMock; - /** - * @var string - */ + /** @var string */ protected $composerJsonPath; - /** - * @var string - */ + /** @var string */ protected $configuratorPath; - /** - * @var \Narrowspark\Automatic\Installer\AbstractInstaller - */ + /** @var \Narrowspark\Automatic\Installer\AbstractInstaller */ protected $installerClass; /** diff --git a/tests/Automatic/Installer/InstallationManagerTest.php b/tests/Automatic/Installer/InstallationManagerTest.php index eb440c30..7b4a2885 100644 --- a/tests/Automatic/Installer/InstallationManagerTest.php +++ b/tests/Automatic/Installer/InstallationManagerTest.php @@ -20,14 +20,10 @@ final class InstallationManagerTest extends MockeryTestCase { use ArrangeComposerClasses; - /** - * @var \Composer\Package\Package|\Mockery\MockInterface - */ + /** @var \Composer\Package\Package|\Mockery\MockInterface */ private $rootPackageMock; - /** - * @var \Composer\Repository\RepositoryInterface|\Mockery\MockInterface - */ + /** @var \Composer\Repository\RepositoryInterface|\Mockery\MockInterface */ private $localRepositoryMock; /** diff --git a/tests/Automatic/LegacyTagsManagerTest.php b/tests/Automatic/LegacyTagsManagerTest.php index 8932d15d..99f55099 100644 --- a/tests/Automatic/LegacyTagsManagerTest.php +++ b/tests/Automatic/LegacyTagsManagerTest.php @@ -11,19 +11,13 @@ */ final class LegacyTagsManagerTest extends MockeryTestCase { - /** - * @var array - */ + /** @var array */ private $downloadFileList; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ private $ioMock; - /** - * @var \Narrowspark\Automatic\LegacyTagsManager - */ + /** @var \Narrowspark\Automatic\LegacyTagsManager */ private $tagsManger; /** diff --git a/tests/Automatic/LockTest.php b/tests/Automatic/LockTest.php index 2f8e8dd2..fb21adc0 100644 --- a/tests/Automatic/LockTest.php +++ b/tests/Automatic/LockTest.php @@ -10,9 +10,7 @@ */ final class LockTest extends TestCase { - /** - * @var \Narrowspark\Automatic\Lock - */ + /** @var \Narrowspark\Automatic\Lock */ private $lock; public static function tearDownAfterClass(): void diff --git a/tests/Automatic/Operation/InstallTest.php b/tests/Automatic/Operation/InstallTest.php index 96f1a35b..3865fbad 100644 --- a/tests/Automatic/Operation/InstallTest.php +++ b/tests/Automatic/Operation/InstallTest.php @@ -25,19 +25,13 @@ final class InstallTest extends MockeryTestCase { use ArrangeOperationsClasses; - /** - * @var \Composer\DependencyResolver\Operation\InstallOperation|\Mockery\MockInterface - */ + /** @var \Composer\DependencyResolver\Operation\InstallOperation|\Mockery\MockInterface */ private $installOperationMock; - /** - * @var \Composer\DependencyResolver\Operation\UpdateOperation|\Mockery\MockInterface - */ + /** @var \Composer\DependencyResolver\Operation\UpdateOperation|\Mockery\MockInterface */ private $updateOperationMock; - /** - * @var \Narrowspark\Automatic\Operation\Install - */ + /** @var \Narrowspark\Automatic\Operation\Install */ private $install; /** @@ -262,7 +256,6 @@ public function testTransformWithScriptsExecutor(): void $packageName = 'Test/TransformWithScriptsExecutor'; - /** @var \Mockery\MockInterface $package */ [$package, $name] = $this->arrangeTransformPackage($packageName, $autoload, $packageData); $package->shouldReceive('getConfig') diff --git a/tests/Automatic/Operation/Traits/ArrangeOperationsClasses.php b/tests/Automatic/Operation/Traits/ArrangeOperationsClasses.php index 0a1fb350..30a4bb65 100644 --- a/tests/Automatic/Operation/Traits/ArrangeOperationsClasses.php +++ b/tests/Automatic/Operation/Traits/ArrangeOperationsClasses.php @@ -11,39 +11,25 @@ trait ArrangeOperationsClasses { - /** - * @var \Narrowspark\Automatic\Configurator - */ + /** @var \Narrowspark\Automatic\Configurator */ protected $configurator; - /** - * @var \Narrowspark\Automatic\PackageConfigurator - */ + /** @var \Narrowspark\Automatic\PackageConfigurator */ protected $packageConfigurator; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ protected $ioMock; - /** - * @var \Mockery\MockInterface|\Narrowspark\Automatic\Lock - */ + /** @var \Mockery\MockInterface|\Narrowspark\Automatic\Lock */ protected $lockMock; - /** - * @var \Narrowspark\Automatic\Common\ClassFinder - */ + /** @var \Narrowspark\Automatic\Common\ClassFinder */ protected $classFinder; - /** - * @var \Composer\Composer|\Mockery\MockInterface - */ + /** @var \Composer\Composer|\Mockery\MockInterface */ protected $composerMock; - /** - * @var string - */ + /** @var string */ private $fixturePath; protected function arrangeOperationsClasses(): void diff --git a/tests/Automatic/Operation/UninstallTest.php b/tests/Automatic/Operation/UninstallTest.php index 53b8198d..730a26f4 100644 --- a/tests/Automatic/Operation/UninstallTest.php +++ b/tests/Automatic/Operation/UninstallTest.php @@ -21,14 +21,10 @@ final class UninstallTest extends MockeryTestCase { use ArrangeOperationsClasses; - /** - * @var \Composer\DependencyResolver\Operation\UninstallOperation|\Mockery\MockInterface - */ + /** @var \Composer\DependencyResolver\Operation\UninstallOperation|\Mockery\MockInterface */ private $uninstallOperationMock; - /** - * @var \Narrowspark\Automatic\Operation\Install - */ + /** @var \Narrowspark\Automatic\Operation\Install */ private $uninstall; /** diff --git a/tests/Automatic/Prefetcher/ParallelDownloaderTest.php b/tests/Automatic/Prefetcher/ParallelDownloaderTest.php index 1def62f5..7be8945c 100644 --- a/tests/Automatic/Prefetcher/ParallelDownloaderTest.php +++ b/tests/Automatic/Prefetcher/ParallelDownloaderTest.php @@ -15,9 +15,7 @@ final class ParallelDownloaderTest extends MockeryTestCase { use ArrangeComposerClasses; - /** - * @var \Narrowspark\Automatic\Prefetcher\ParallelDownloader - */ + /** @var \Narrowspark\Automatic\Prefetcher\ParallelDownloader */ private $parallelDownloader; /** diff --git a/tests/Automatic/ScriptExecutorTest.php b/tests/Automatic/ScriptExecutorTest.php index 741bb55f..92c7ed99 100644 --- a/tests/Automatic/ScriptExecutorTest.php +++ b/tests/Automatic/ScriptExecutorTest.php @@ -16,24 +16,16 @@ */ final class ScriptExecutorTest extends MockeryTestCase { - /** - * @var \Composer\Composer - */ + /** @var \Composer\Composer */ private $composer; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ private $ioMock; - /** - * @var \Composer\Util\ProcessExecutor|\Mockery\MockInterface - */ + /** @var \Composer\Util\ProcessExecutor|\Mockery\MockInterface */ private $processExecutorMock; - /** - * @var \Narrowspark\Automatic\ScriptExecutor - */ + /** @var \Narrowspark\Automatic\ScriptExecutor */ private $scriptExecutor; /** diff --git a/tests/Automatic/ScriptExtender/ScriptExtenderTest.php b/tests/Automatic/ScriptExtender/ScriptExtenderTest.php index ffb95553..2ba5c170 100644 --- a/tests/Automatic/ScriptExtender/ScriptExtenderTest.php +++ b/tests/Automatic/ScriptExtender/ScriptExtenderTest.php @@ -12,9 +12,7 @@ */ final class ScriptExtenderTest extends TestCase { - /** - * @var \Narrowspark\Automatic\ScriptExtender\ScriptExtender - */ + /** @var \Narrowspark\Automatic\ScriptExtender\ScriptExtender */ private $extender; /** diff --git a/tests/Automatic/SkeletonGeneratorTest.php b/tests/Automatic/SkeletonGeneratorTest.php index 5a23d2fd..6dcd65df 100644 --- a/tests/Automatic/SkeletonGeneratorTest.php +++ b/tests/Automatic/SkeletonGeneratorTest.php @@ -19,24 +19,16 @@ */ final class SkeletonGeneratorTest extends MockeryTestCase { - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ private $ioMock; - /** - * @var \Mockery\MockInterface|\Narrowspark\Automatic\Installer\InstallationManager - */ + /** @var \Mockery\MockInterface|\Narrowspark\Automatic\Installer\InstallationManager */ private $installationManagerMock; - /** - * @var \Mockery\MockInterface|\Narrowspark\Automatic\Lock - */ + /** @var \Mockery\MockInterface|\Narrowspark\Automatic\Lock */ private $lockMock; - /** - * @var \Narrowspark\Automatic\SkeletonGenerator - */ + /** @var \Narrowspark\Automatic\SkeletonGenerator */ private $skeletonGenerator; /** @@ -79,7 +71,7 @@ public function testRun(): void ->once() ->withArgs(static function ($requires, $devRequires) { Assert::assertInstanceOf(Package::class, $requires[0]); - Assert::assertInternalType('array', $devRequires); + Assert::assertIsArray($devRequires); return true; }); diff --git a/tests/Automatic/Traits/ArrangeComposerClasses.php b/tests/Automatic/Traits/ArrangeComposerClasses.php index 52a1fcb0..7d482506 100644 --- a/tests/Automatic/Traits/ArrangeComposerClasses.php +++ b/tests/Automatic/Traits/ArrangeComposerClasses.php @@ -10,34 +10,22 @@ trait ArrangeComposerClasses { - /** - * @var \Composer\Composer|\Mockery\MockInterface - */ + /** @var \Composer\Composer|\Mockery\MockInterface */ protected $composerMock; - /** - * @var \Composer\Config|\Mockery\MockInterface - */ + /** @var \Composer\Config|\Mockery\MockInterface */ protected $configMock; - /** - * @var \Mockery\MockInterface|\Symfony\Component\Console\Input\InputInterface - */ + /** @var \Mockery\MockInterface|\Symfony\Component\Console\Input\InputInterface */ protected $inputMock; - /** - * @var \Composer\IO\IOInterface|\Mockery\MockInterface - */ + /** @var \Composer\IO\IOInterface|\Mockery\MockInterface */ protected $ioMock; - /** - * @var string - */ + /** @var string */ protected $composerCachePath; - /** - * @var \Mockery\MockInterface|\Narrowspark\Automatic\Lock - */ + /** @var \Mockery\MockInterface|\Narrowspark\Automatic\Lock */ protected $lockMock; protected function arrangeComposerClasses(): void diff --git a/tests/Common/Fixture/Finder/DummyClass.php b/tests/Common/Fixture/Finder/DummyClass.php index 4c304c79..36b99b54 100644 --- a/tests/Common/Fixture/Finder/DummyClass.php +++ b/tests/Common/Fixture/Finder/DummyClass.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; -class DummyClass implements ConfiguratorContract +final class DummyClass implements ConfiguratorContract { /** * {@inheritdoc} diff --git a/tests/Common/Fixture/Finder/DummyClassTwo.php b/tests/Common/Fixture/Finder/DummyClassTwo.php index 33d3e753..c5d0099d 100644 --- a/tests/Common/Fixture/Finder/DummyClassTwo.php +++ b/tests/Common/Fixture/Finder/DummyClassTwo.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; -class DummyClassTwo implements ConfiguratorContract +final class DummyClassTwo implements ConfiguratorContract { /** * {@inheritdoc} diff --git a/tests/Common/Fixture/Finder/Nested/DummyClassNested.php b/tests/Common/Fixture/Finder/Nested/DummyClassNested.php index 62976707..2233d20f 100644 --- a/tests/Common/Fixture/Finder/Nested/DummyClassNested.php +++ b/tests/Common/Fixture/Finder/Nested/DummyClassNested.php @@ -5,7 +5,7 @@ use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract; use Narrowspark\Automatic\Common\Contract\Package as PackageContract; -class DummyClassNested implements ConfiguratorContract +final class DummyClassNested implements ConfiguratorContract { /** * {@inheritdoc} diff --git a/tests/Common/Fixture/Finder/StaticFunctionAndClasses.php b/tests/Common/Fixture/Finder/StaticFunctionAndClasses.php index 8eee5b75..9cc2757b 100644 --- a/tests/Common/Fixture/Finder/StaticFunctionAndClasses.php +++ b/tests/Common/Fixture/Finder/StaticFunctionAndClasses.php @@ -7,7 +7,7 @@ use Psr\Http\Message\StreamFactoryInterface; use Viserio\Component\View\ViewFactory; -class StaticFunctionAndClasses +final class StaticFunctionAndClasses { public static function getInstanceIdentifier() { diff --git a/tests/Common/PackageTest.php b/tests/Common/PackageTest.php index a80c28d0..5faadb8d 100644 --- a/tests/Common/PackageTest.php +++ b/tests/Common/PackageTest.php @@ -11,9 +11,7 @@ */ final class PackageTest extends TestCase { - /** - * @var \Narrowspark\Automatic\Common\Package - */ + /** @var \Narrowspark\Automatic\Common\Package */ private $package; /** diff --git a/tests/Common/PathTest.php b/tests/Common/PathTest.php index 8cacaf5c..c8b6414f 100644 --- a/tests/Common/PathTest.php +++ b/tests/Common/PathTest.php @@ -10,9 +10,7 @@ */ final class PathTest extends TestCase { - /** - * @var \Narrowspark\Automatic\Common\Path - */ + /** @var \Narrowspark\Automatic\Common\Path */ private $path; /** @@ -45,4 +43,32 @@ public function testConcatenateOnWindows(): void $this->path->concatenate(['c:' . \DIRECTORY_SEPARATOR . 'my-project', 'src' . \DIRECTORY_SEPARATOR, 'kernel.php']) ); } + + /** + * @dataProvider providePathsForConcatenation + * + * @param string $part1 + * @param string $part2 + * @param string $expectedPath + */ + public function testConcatenate(string $part1, string $part2, string $expectedPath): void + { + $actualPath = $this->path->concatenate([$part1, $part2]); + + $this->assertSame($expectedPath, $actualPath); + } + + /** + * @return array + */ + public function providePathsForConcatenation(): array + { + return [ + [__DIR__, 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', __DIR__ . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + [__DIR__, \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', __DIR__ . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + ['', 'foo/bar.txt', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + ['', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + ['.', 'foo/bar.txt', '.' . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + ]; + } } diff --git a/tests/Common/ScriptExtender/PhpScriptExtenderTest.php b/tests/Common/ScriptExtender/PhpScriptExtenderTest.php index b02870e4..eb27a277 100644 --- a/tests/Common/ScriptExtender/PhpScriptExtenderTest.php +++ b/tests/Common/ScriptExtender/PhpScriptExtenderTest.php @@ -12,9 +12,7 @@ */ final class PhpScriptExtenderTest extends TestCase { - /** - * @var \Narrowspark\Automatic\Common\ScriptExtender\PhpScriptExtender - */ + /** @var \Narrowspark\Automatic\Common\ScriptExtender\PhpScriptExtender */ private $extender; /** diff --git a/tests/Common/Traits/PhpFileMarkerTraitTest.php b/tests/Common/Traits/PhpFileMarkerTraitTest.php index b74241f4..a00e49de 100644 --- a/tests/Common/Traits/PhpFileMarkerTraitTest.php +++ b/tests/Common/Traits/PhpFileMarkerTraitTest.php @@ -12,9 +12,7 @@ final class PhpFileMarkerTraitTest extends TestCase { use PhpFileMarkerTrait; - /** - * @var string - */ + /** @var string */ private $path; protected function setUp(): void diff --git a/tests/Security/AuditTest.php b/tests/Security/AuditTest.php index f841e9ac..b35b7f9d 100644 --- a/tests/Security/AuditTest.php +++ b/tests/Security/AuditTest.php @@ -12,14 +12,10 @@ */ final class AuditTest extends TestCase { - /** - * @var \Narrowspark\Automatic\Security\Audit - */ + /** @var \Narrowspark\Automatic\Security\Audit */ private $audit; - /** - * @var string - */ + /** @var string */ private $path; /** diff --git a/tests/Security/Command/AuditCommandTest.php b/tests/Security/Command/AuditCommandTest.php index 870f3547..66cff3ec 100644 --- a/tests/Security/Command/AuditCommandTest.php +++ b/tests/Security/Command/AuditCommandTest.php @@ -14,19 +14,13 @@ */ final class AuditCommandTest extends TestCase { - /** - * @var \Composer\Console\Application - */ + /** @var \Composer\Console\Application */ private $application; - /** - * @var string - */ + /** @var string */ private $greenString; - /** - * @var string - */ + /** @var string */ private $redString; /** diff --git a/tests/Security/Downloader/ComposerDownloaderTest.php b/tests/Security/Downloader/ComposerDownloaderTest.php index 8df241fe..ba790d2a 100644 --- a/tests/Security/Downloader/ComposerDownloaderTest.php +++ b/tests/Security/Downloader/ComposerDownloaderTest.php @@ -10,14 +10,10 @@ */ final class ComposerDownloaderTest extends TestCase { - /** - * @var string - */ + /** @var string */ private const SECURITY_ADVISORIES_SHA = 'https://raw.githubusercontent.com/narrowspark/security-advisories/master/security-advisories-sha'; - /** - * @var \Narrowspark\Automatic\Security\Downloader\ComposerDownloader - */ + /** @var \Narrowspark\Automatic\Security\Downloader\ComposerDownloader */ private $downloader; /** diff --git a/tests/Security/Downloader/CurlDownloaderTest.php b/tests/Security/Downloader/CurlDownloaderTest.php index 06014e23..68af4312 100644 --- a/tests/Security/Downloader/CurlDownloaderTest.php +++ b/tests/Security/Downloader/CurlDownloaderTest.php @@ -10,14 +10,10 @@ */ final class CurlDownloaderTest extends TestCase { - /** - * @var string - */ + /** @var string */ private const SECURITY_ADVISORIES_SHA = 'https://raw.githubusercontent.com/narrowspark/security-advisories/master/security-advisories-sha'; - /** - * @var \Narrowspark\Automatic\Security\Downloader\CurlDownloader - */ + /** @var \Narrowspark\Automatic\Security\Downloader\CurlDownloader */ private $downloader; /** diff --git a/tests/Security/SecurityPluginTest.php b/tests/Security/SecurityPluginTest.php index 1e6c1836..9c884127 100644 --- a/tests/Security/SecurityPluginTest.php +++ b/tests/Security/SecurityPluginTest.php @@ -26,14 +26,10 @@ final class SecurityPluginTest extends MockeryTestCase { use ArrangeComposerClasses; - /** - * @var \Narrowspark\Automatic\Security\SecurityPlugin - */ + /** @var \Narrowspark\Automatic\Security\SecurityPlugin */ private $securityPlugin; - /** - * @var string - */ + /** @var string */ private $tmpFolder; /** From 074ccda98f1f3d6487d2007c6f6a9236921a089e Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 22:10:45 +0200 Subject: [PATCH 03/10] fix: don't output emojis when the output isn't being decorated --- src/Automatic/Automatic.php | 2 +- src/Automatic/Prefetcher/ParallelDownloader.php | 8 ++++++-- src/Security/SecurityPlugin.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Automatic/Automatic.php b/src/Automatic/Automatic.php index e81594aa..71f346d5 100644 --- a/src/Automatic/Automatic.php +++ b/src/Automatic/Automatic.php @@ -200,7 +200,7 @@ public function activate(Composer $composer, IOInterface $io): void foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\dirname(__DIR__, 1), FilesystemIterator::SKIP_DOTS)) as $file) { /** @var \SplFileInfo $file */ if (\substr($file->getFilename(), -4) === '.php') { - class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__), -4))); + \class_exists(__NAMESPACE__ . \str_replace('/', '\\', \substr($file, \strlen(__DIR__), -4))); } } diff --git a/src/Automatic/Prefetcher/ParallelDownloader.php b/src/Automatic/Prefetcher/ParallelDownloader.php index 54ce4203..1057beee 100644 --- a/src/Automatic/Prefetcher/ParallelDownloader.php +++ b/src/Automatic/Prefetcher/ParallelDownloader.php @@ -174,8 +174,12 @@ public function download(array &$nextArgs, callable $nextCallback, bool $quiet = $this->io->writeError('Enable the "cURL" PHP extension for faster downloads'); } - $note = \DIRECTORY_SEPARATOR === '\\' ? '' : (\stripos(\PHP_OS, 'darwin') !== false ? '🎵' : '🎶'); - $note .= $this->downloader !== null ? (\DIRECTORY_SEPARATOR !== '\\' ? ' 💨' : '') : ''; + $note = ''; + + if ($this->io->isDecorated()) { + $note = \DIRECTORY_SEPARATOR === '\\' ? '' : (false !== \stripos(\PHP_OS, 'darwin') ? '🎵' : '🎶'); + $note .= $this->downloader ? (\DIRECTORY_SEPARATOR !== '\\' ? ' 💨' : '') : ''; + } $this->io->writeError(''); $this->io->writeError(\sprintf('Prefetching %d packages %s', $this->downloadCount, $note)); diff --git a/src/Security/SecurityPlugin.php b/src/Security/SecurityPlugin.php index 6bd699a0..416e7fda 100644 --- a/src/Security/SecurityPlugin.php +++ b/src/Security/SecurityPlugin.php @@ -109,7 +109,7 @@ public function activate(Composer $composer, IOInterface $io): void foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS)) as $file) { /** @var \SplFileInfo $file */ if (\substr($file->getFilename(), -4) === '.php') { - class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__), -4))); + \class_exists(__NAMESPACE__ . \str_replace('/', '\\', \substr($file, \strlen(__DIR__), -4))); } } From b58cecffdce89acd2ae17d4810bdec61ff4d8a91 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 22:19:04 +0200 Subject: [PATCH 04/10] feat: drop php 7.1 support fix: use $file->getFilename() on class_exists --- .travis.yml | 13 +++-- appveyor.yml | 3 ++ composer.json | 8 +-- phpunit.xml.dist | 8 ++- src/Automatic/Automatic.php | 2 +- src/Security/SecurityPlugin.php | 2 +- .../Installer/InstallationManagerTest.php | 4 +- tests/Automatic/LegacyTagsManagerTest.php | 2 +- tests/Automatic/QuestionFactoryTest.php | 10 ++-- .../ScriptExtender/PhpScriptExtenderTest.php | 12 ++--- tests/Security/Command/AuditCommandTest.php | 50 +++++++++---------- 11 files changed, 63 insertions(+), 51 deletions(-) diff --git a/.travis.yml b/.travis.yml index 067bf09f..6caa7da4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ jobs: - php: 7.4 include: - stage: Test - php: 7.1 + php: 7.2 env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true COMPOSER_VERSION=1.6.5 - stage: Test php: 7.2 @@ -55,22 +55,25 @@ jobs: - stage: Test php: 7.3 env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.8.0 + - stage: Test + php: 7.3 + env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.9.0 - stage: Test php: 7.4 - env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.8.0 + env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.9.0 - stage: Test php: nightly - env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.8.0 + env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.9.0 - stage: Static Analysis php: 7.2 - env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.8.0 + env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.9.0 script: - composer phpstan - stage: Coverage php: 7.2 - env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.8.0 + env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.9.0 script: - bash -xc "$TEST -c ./phpunit.xml.dist --coverage-clover=coverage.xml" after_success: diff --git a/appveyor.yml b/appveyor.yml index 781936ad..b263be31 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,6 +16,9 @@ environment: - dependencies: high PHP_VERSION: 7.3 COMPOSER_VERSION: 1.8.0 + - dependencies: high + PHP_VERSION: 7.3 + COMPOSER_VERSION: 1.9.0 matrix: fast_finish: true diff --git a/composer.json b/composer.json index b8d23fae..671b40bf 100644 --- a/composer.json +++ b/composer.json @@ -25,17 +25,17 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "ext-json": "*", "ext-tokenizer": "*", "composer-plugin-api": "^1.0" }, "require-dev": { - "composer/composer": "^1.6.5 || ^1.7.0 || ^1.8.0", + "composer/composer": "^1.6.5 || ^1.7.0 || ^1.8.0 || ^1.9.0", "mockery/mockery": "^1.0.0", - "narrowspark/testing-helper": "^6.0.0", + "narrowspark/testing-helper": "^8.0.0", "nyholm/nsa": "^1.1.0", - "phpunit/phpunit": "^7.2.0", + "phpunit/phpunit": "^8.3.3", "ocramius/package-versions": "^1.4.0", "narrowspark/coding-standard": "^2.0.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 24e2f3bc..dcec5a1f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,11 +1,17 @@ diff --git a/src/Automatic/Automatic.php b/src/Automatic/Automatic.php index 71f346d5..ea1a1cc5 100644 --- a/src/Automatic/Automatic.php +++ b/src/Automatic/Automatic.php @@ -200,7 +200,7 @@ public function activate(Composer $composer, IOInterface $io): void foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\dirname(__DIR__, 1), FilesystemIterator::SKIP_DOTS)) as $file) { /** @var \SplFileInfo $file */ if (\substr($file->getFilename(), -4) === '.php') { - \class_exists(__NAMESPACE__ . \str_replace('/', '\\', \substr($file, \strlen(__DIR__), -4))); + \class_exists(__NAMESPACE__ . \str_replace('/', '\\', \substr($file->getFilename(), \strlen(__DIR__), -4))); } } diff --git a/src/Security/SecurityPlugin.php b/src/Security/SecurityPlugin.php index 416e7fda..c33ffba8 100644 --- a/src/Security/SecurityPlugin.php +++ b/src/Security/SecurityPlugin.php @@ -109,7 +109,7 @@ public function activate(Composer $composer, IOInterface $io): void foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS)) as $file) { /** @var \SplFileInfo $file */ if (\substr($file->getFilename(), -4) === '.php') { - \class_exists(__NAMESPACE__ . \str_replace('/', '\\', \substr($file, \strlen(__DIR__), -4))); + \class_exists(__NAMESPACE__ . \str_replace('/', '\\', \substr($file->getFilename(), \strlen(__DIR__), -4))); } } diff --git a/tests/Automatic/Installer/InstallationManagerTest.php b/tests/Automatic/Installer/InstallationManagerTest.php index 7b4a2885..9c676d89 100644 --- a/tests/Automatic/Installer/InstallationManagerTest.php +++ b/tests/Automatic/Installer/InstallationManagerTest.php @@ -122,8 +122,8 @@ public function testInstallWithRequireAndNoPackageVersion(): void $this->ioMock->shouldReceive('writeError') ->withArgs(static function ($string) { - Assert::assertContains('Using version ', $string); - Assert::assertContains('for symfony/symfony', $string); + Assert::assertStringContainsString('Using version ', $string); + Assert::assertStringContainsString('for symfony/symfony', $string); return true; }); diff --git a/tests/Automatic/LegacyTagsManagerTest.php b/tests/Automatic/LegacyTagsManagerTest.php index 99f55099..32c991a5 100644 --- a/tests/Automatic/LegacyTagsManagerTest.php +++ b/tests/Automatic/LegacyTagsManagerTest.php @@ -173,7 +173,7 @@ public function provideRemoveLegacyTags(): \Generator yield 'empty-intersection-ignores' => [$packages, $packages, '~2.0']; - yield 'empty-intersection-ignores' => [$packages, $packages, '~4.0']; + yield 'empty-intersection-ignores2' => [$packages, $packages, '~4.0']; $expected = $packages; diff --git a/tests/Automatic/QuestionFactoryTest.php b/tests/Automatic/QuestionFactoryTest.php index ebbbfa60..26db0d56 100644 --- a/tests/Automatic/QuestionFactoryTest.php +++ b/tests/Automatic/QuestionFactoryTest.php @@ -19,8 +19,8 @@ public function testGetPackageQuestion(): void $message = QuestionFactory::getPackageQuestion($name, $url); $this->assertNotEmpty($message); - $this->assertContains($url, $message); - $this->assertContains($name, $message); + $this->assertStringContainsString($url, $message); + $this->assertStringContainsString($name, $message); } public function testGetPackageQuestionWithoutUrl(): void @@ -31,8 +31,8 @@ public function testGetPackageQuestionWithoutUrl(): void $message = QuestionFactory::getPackageQuestion($name, null); $this->assertNotEmpty($message); - $this->assertNotContains($url, $message); - $this->assertContains($name, $message); + $this->assertStringNotContainsString($url, $message); + $this->assertStringContainsString($name, $message); } public function testGetPackageScriptsQuestion(): void @@ -42,7 +42,7 @@ public function testGetPackageScriptsQuestion(): void $message = QuestionFactory::getPackageScriptsQuestion($name); $this->assertNotEmpty($message); - $this->assertContains($name, $message); + $this->assertStringContainsString($name, $message); } public function testValidatePackageQuestionAnswer(): void diff --git a/tests/Common/ScriptExtender/PhpScriptExtenderTest.php b/tests/Common/ScriptExtender/PhpScriptExtenderTest.php index eb27a277..d2447585 100644 --- a/tests/Common/ScriptExtender/PhpScriptExtenderTest.php +++ b/tests/Common/ScriptExtender/PhpScriptExtenderTest.php @@ -34,9 +34,9 @@ public function testExpand(): void { $output = $this->extender->expand('echo "hallo";'); - $this->assertContains('php', $output); - $this->assertContains('php.ini', $output); - $this->assertContains('echo "hallo";', $output); + $this->assertStringContainsString('php', $output); + $this->assertStringContainsString('php.ini', $output); + $this->assertStringContainsString('echo "hallo";', $output); } public function testExpandWithIniLoad(): void @@ -47,8 +47,8 @@ public function testExpandWithIniLoad(): void $output = $this->extender->expand('echo "hallo";'); - $this->assertContains('php', $output); - $this->assertContains('php.ini', $output); - $this->assertContains('echo "hallo";', $output); + $this->assertStringContainsString('php', $output); + $this->assertStringContainsString('php.ini', $output); + $this->assertStringContainsString('echo "hallo";', $output); } } diff --git a/tests/Security/Command/AuditCommandTest.php b/tests/Security/Command/AuditCommandTest.php index 66cff3ec..86c18091 100644 --- a/tests/Security/Command/AuditCommandTest.php +++ b/tests/Security/Command/AuditCommandTest.php @@ -44,7 +44,7 @@ public function testAuditCommand(): void $commandTester = $this->executeCommand(new AuditCommand()); - $this->assertContains($this->greenString . ' No known vulnerabilities found', \trim($commandTester->getDisplay(true))); + $this->assertStringContainsString($this->greenString . ' No known vulnerabilities found', \trim($commandTester->getDisplay(true))); \putenv('COMPOSER='); \putenv('COMPOSER'); @@ -59,9 +59,9 @@ public function testAuditCommandWithComposerLockOption(): void $output = \trim($commandTester->getDisplay(true)); - $this->assertContains('=== Audit Security Report ===', $output); - $this->assertContains('This checker can only detect vulnerabilities that are referenced', $output); - $this->assertContains($this->greenString . ' No known vulnerabilities found', $output); + $this->assertStringContainsString('=== Audit Security Report ===', $output); + $this->assertStringContainsString('This checker can only detect vulnerabilities that are referenced', $output); + $this->assertStringContainsString($this->greenString . ' No known vulnerabilities found', $output); } public function testAuditCommandWithEmptyComposerLockPath(): void @@ -73,8 +73,8 @@ public function testAuditCommandWithEmptyComposerLockPath(): void $output = \trim($commandTester->getDisplay(true)); - $this->assertContains(\trim('=== Audit Security Report ==='), $output); - $this->assertContains(\trim('Lock file does not exist.'), $output); + $this->assertStringContainsString(\trim('=== Audit Security Report ==='), $output); + $this->assertStringContainsString(\trim('Lock file does not exist.'), $output); } public function testAuditCommandWithError(): void @@ -86,10 +86,10 @@ public function testAuditCommandWithError(): void $output = \trim($commandTester->getDisplay(true)); - $this->assertContains('=== Audit Security Report ===', $output); - $this->assertContains('This checker can only detect vulnerabilities that are referenced', $output); - $this->assertContains('symfony/symfony (v2.5.2)', $output); - $this->assertContains($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); + $this->assertStringContainsString('=== Audit Security Report ===', $output); + $this->assertStringContainsString('This checker can only detect vulnerabilities that are referenced', $output); + $this->assertStringContainsString('symfony/symfony (v2.5.2)', $output); + $this->assertStringContainsString($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); $this->assertSame(1, $commandTester->getStatusCode()); } @@ -105,10 +105,10 @@ public function testAuditCommandWithErrorAndZeroExitCode(): void $output = \trim($commandTester->getDisplay(true)); - $this->assertContains('=== Audit Security Report ===', $output); - $this->assertContains('This checker can only detect vulnerabilities that are referenced', $output); - $this->assertContains('symfony/symfony (v2.5.2)', $output); - $this->assertContains($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); + $this->assertStringContainsString('=== Audit Security Report ===', $output); + $this->assertStringContainsString('This checker can only detect vulnerabilities that are referenced', $output); + $this->assertStringContainsString('symfony/symfony (v2.5.2)', $output); + $this->assertStringContainsString($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); $this->assertSame(0, $commandTester->getStatusCode()); } @@ -124,10 +124,10 @@ public function testAuditCommandWithErrorZeroExitCodeAndOneVulnerability(): void $output = \trim($commandTester->getDisplay(true)); - $this->assertContains('=== Audit Security Report ===', $output); - $this->assertContains('This checker can only detect vulnerabilities that are referenced', $output); - $this->assertContains('3f/pygmentize (1.1)', $output); - $this->assertContains($this->redString . ' 1 vulnerability found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); + $this->assertStringContainsString('=== Audit Security Report ===', $output); + $this->assertStringContainsString('This checker can only detect vulnerabilities that are referenced', $output); + $this->assertStringContainsString('3f/pygmentize (1.1)', $output); + $this->assertStringContainsString($this->redString . ' 1 vulnerability found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); $this->assertSame(0, $commandTester->getStatusCode()); } @@ -145,9 +145,9 @@ public function testAuditCommandWithErrorAndJsonFormat(): void $output = \trim($commandTester->getDisplay(true)); $this->assertJson(\strstr(\substr($output, 0, \strrpos($output, '}') + 1), '{')); - $this->assertContains('=== Audit Security Report ===', $output); - $this->assertContains('This checker can only detect vulnerabilities that are referenced', $output); - $this->assertContains($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); + $this->assertStringContainsString('=== Audit Security Report ===', $output); + $this->assertStringContainsString('This checker can only detect vulnerabilities that are referenced', $output); + $this->assertStringContainsString($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); } public function testAuditCommandWithErrorAndSimpleFormat(): void @@ -162,12 +162,12 @@ public function testAuditCommandWithErrorAndSimpleFormat(): void $output = \trim($commandTester->getDisplay(true)); - $this->assertContains('=== Audit Security Report ===', $output); - $this->assertContains(\trim('symfony/symfony (v2.5.2) + $this->assertStringContainsString('=== Audit Security Report ===', $output); + $this->assertStringContainsString(\trim('symfony/symfony (v2.5.2) ------------------------ '), $output); - $this->assertContains('This checker can only detect vulnerabilities that are referenced', $output); - $this->assertContains($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); + $this->assertStringContainsString('This checker can only detect vulnerabilities that are referenced', $output); + $this->assertStringContainsString($this->redString . ' 2 vulnerabilities found - We recommend you to check the related security advisories and upgrade these dependencies.', $output); } /** From 17b4dc9faec25356a1e6c0977c10a566665167c6 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 23:13:56 +0200 Subject: [PATCH 05/10] feat: added php7.4 to travis --- .travis.yml | 4 ++-- composer.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6caa7da4..d14fcccf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,7 +44,7 @@ script: jobs: allow_failures: - php: nightly - - php: 7.4 + - php: 7.4snapshot include: - stage: Test php: 7.2 @@ -59,7 +59,7 @@ jobs: php: 7.3 env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.9.0 - stage: Test - php: 7.4 + php: 7.4snapshot env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.9.0 - stage: Test php: nightly diff --git a/composer.json b/composer.json index 671b40bf..8cf2475b 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,11 @@ }, "require-dev": { "composer/composer": "^1.6.5 || ^1.7.0 || ^1.8.0 || ^1.9.0", - "mockery/mockery": "^1.0.0", + "mockery/mockery": "^1.2.2", "narrowspark/testing-helper": "^8.0.0", "nyholm/nsa": "^1.1.0", "phpunit/phpunit": "^8.3.3", - "ocramius/package-versions": "^1.4.0", + "ocramius/package-versions": "^1.4.0 || ^1.5.0", "narrowspark/coding-standard": "^2.0.0" }, "config": { From 08e23e9ebdfed0cafc92078019015c8a9a39afbe Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 23:17:09 +0200 Subject: [PATCH 06/10] feat: dropped support for composer v1.6.5 --- .travis.yml | 3 --- composer.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d14fcccf..4b16e035 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,9 +46,6 @@ jobs: - php: nightly - php: 7.4snapshot include: - - stage: Test - php: 7.2 - env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true COMPOSER_VERSION=1.6.5 - stage: Test php: 7.2 env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.7.0 diff --git a/composer.json b/composer.json index 8cf2475b..0026ab99 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "composer-plugin-api": "^1.0" }, "require-dev": { - "composer/composer": "^1.6.5 || ^1.7.0 || ^1.8.0 || ^1.9.0", + "composer/composer": "^1.7.0 || ^1.8.0 || ^1.9.0", "mockery/mockery": "^1.2.2", "narrowspark/testing-helper": "^8.0.0", "nyholm/nsa": "^1.1.0", From 01f188d1a9bc290e497853544e2406f66ca79f2e Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sat, 10 Aug 2019 23:26:12 +0200 Subject: [PATCH 07/10] feat: dropped support for composer v1.6.5 feat: added infection feat: changed phpunit settings to run tests in random order feat: updated narrowspark/coding-standard to v2.1.1 --- .gitattributes | 27 ++++----- .gitignore | 2 + .prettyci.composer.json | 5 -- .travis.yml | 14 +++++ appveyor.yml | 2 +- composer.json | 15 +++-- infection.json.dist | 14 +++++ phpunit.xml.dist | 7 ++- psalm.xml | 55 +++++++++++++++++++ src/Automatic/Automatic.php | 2 +- src/Security/SecurityPlugin.php | 2 +- tests/Automatic/AutomaticTest.php | 10 ++++ .../ComposerAutoScriptsConfiguratorTest.php | 8 +++ .../Fixture/composer-empty-scripts.json | 12 ++++ 14 files changed, 148 insertions(+), 27 deletions(-) delete mode 100644 .prettyci.composer.json create mode 100644 infection.json.dist create mode 100644 psalm.xml create mode 100644 tests/Automatic/Fixture/composer-empty-scripts.json diff --git a/.gitattributes b/.gitattributes index 523e2f5c..44ad0a16 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,17 +1,18 @@ * text=auto *.php text eol=lf -tests/ export-ignore -build export-ignore -.github export-ignore +tests/ export-ignore +build/ export-ignore +.github/ export-ignore -.php_cs export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.travis.yml export-ignore -.editorconfig export-ignore -codecov.yml export-ignore -phpstan.neon export-ignore -phpunit.xml.dist export-ignore -CONTRIBUTING.md export-ignore -README.md export-ignore +.php_cs export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +.editorconfig export-ignore +codecov.yml export-ignore +phpstan.neon export-ignore +phpunit.xml.dist export-ignore +infection.json.dist export-ignore +CONTRIBUTING.md export-ignore +README.md export-ignore diff --git a/.gitignore b/.gitignore index 7a7c9725..a61a84dd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ composer.lock .php_cs.cache .phpunit.result.cache +infectionlog.json +infectionlog.txt /build/logs /vendor diff --git a/.prettyci.composer.json b/.prettyci.composer.json deleted file mode 100644 index 6e0e891a..00000000 --- a/.prettyci.composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require-dev": { - "narrowspark/php-cs-fixer-config": "^3.4.0" - } -} diff --git a/.travis.yml b/.travis.yml index 4b16e035..aed3358c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,9 @@ jobs: - php: nightly - php: 7.4snapshot include: + - stage: Test + php: 7.2 + env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true COMPOSER_VERSION=1.7.0 - stage: Test php: 7.2 env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.7.0 @@ -67,6 +70,17 @@ jobs: env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.9.0 script: - composer phpstan +# - stage: Static Analysis +# php: 7.2 +# env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.9.0 +# script: +# - composer psalm + + - stage: Mutation + php: 7.2 + env: REMOVE_XDEBUG=true SETUP=high COMPOSER_VERSION=1.9.0 + script: + - ulimit -n 4096 && phpdbg -qrr ./vendor/bin/infection -vvv --test-framework-options='--testsuite=unit' --min-msi=48 --min-covered-msi=70 - stage: Coverage php: 7.2 diff --git a/appveyor.yml b/appveyor.yml index b263be31..fd172e03 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,7 +9,7 @@ environment: matrix: - dependencies: lowest PHP_VERSION: 7.2 - COMPOSER_VERSION: 1.6.5 + COMPOSER_VERSION: 1.7.0 - dependencies: high PHP_VERSION: 7.2 COMPOSER_VERSION: 1.7.0 diff --git a/composer.json b/composer.json index 0026ab99..4f0ef19b 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "nyholm/nsa": "^1.1.0", "phpunit/phpunit": "^8.3.3", "ocramius/package-versions": "^1.4.0 || ^1.5.0", - "narrowspark/coding-standard": "^2.0.0" + "narrowspark/coding-standard": "^2.1.1", + "infection/infection": "^0.13.4" }, "config": { "optimize-autoloader": true, @@ -45,7 +46,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0.x-dev" }, "class": [ "Narrowspark\\Automatic\\Security\\SecurityPlugin", @@ -66,8 +67,7 @@ "psr-4": { "Narrowspark\\Automatic\\Test\\": "tests/Automatic/", "Narrowspark\\Automatic\\Common\\Test\\": "tests/Common/", - "Narrowspark\\Automatic\\Security\\Test\\": "tests/Security/", - "Narrowspark\\Automatic\\Functional\\Test\\": "tests/Functional/" + "Narrowspark\\Automatic\\Security\\Test\\": "tests/Security/" }, "files": [ "tests/Automatic/TmpDirMock.php" @@ -79,10 +79,15 @@ "coverage": "phpunit --coverage-html=\"build/logs\"", "cs": "php-cs-fixer fix", "phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1", + "psalm": "psalm", "test": "phpunit", + "infection": "infection", "test-common": "phpunit --testsuite=\"Narrowspark Automatic Common Test Suite\"", "test-automatic": "phpunit --testsuite=\"Narrowspark Automatic Test Suite\"", - "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend" + "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend", + "auto-scripts": { + + } }, "support": { "issues": "https://github.com/narrowspark/automatic/issues", diff --git a/infection.json.dist b/infection.json.dist new file mode 100644 index 00000000..f6c770f0 --- /dev/null +++ b/infection.json.dist @@ -0,0 +1,14 @@ +{ + "timeout": 15, + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "text": "infection.log" + }, + "mutators": { + "@default": true + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dcec5a1f..945fb682 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..42f355b2 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Automatic/Automatic.php b/src/Automatic/Automatic.php index ea1a1cc5..08bfd09b 100644 --- a/src/Automatic/Automatic.php +++ b/src/Automatic/Automatic.php @@ -926,7 +926,7 @@ private function getErrorMessage(IOInterface $io): ?string return 'You must enable the openssl extension in your "php.ini" file'; } - if (\version_compare(self::getComposerVersion(), '1.6.0', '<')) { + if (\version_compare(self::getComposerVersion(), '1.7.0', '<')) { return \sprintf('Your version "%s" of Composer is too old; Please upgrade', Composer::VERSION); } diff --git a/src/Security/SecurityPlugin.php b/src/Security/SecurityPlugin.php index c33ffba8..c467be0d 100644 --- a/src/Security/SecurityPlugin.php +++ b/src/Security/SecurityPlugin.php @@ -225,7 +225,7 @@ public function auditComposerLock(Event $event): void private function getErrorMessage(): ?string { // @codeCoverageIgnoreStart - if (\version_compare(self::getComposerVersion(), '1.6.0', '<')) { + if (\version_compare(self::getComposerVersion(), '1.7.0', '<')) { return \sprintf('Your version "%s" of Composer is too old; Please upgrade', Composer::VERSION); } // @codeCoverageIgnoreEnd diff --git a/tests/Automatic/AutomaticTest.php b/tests/Automatic/AutomaticTest.php index 3633f9ef..9e0615dd 100644 --- a/tests/Automatic/AutomaticTest.php +++ b/tests/Automatic/AutomaticTest.php @@ -96,6 +96,8 @@ protected function tearDown(): void public function testGetSubscribedEvents(): void { + NSA::setProperty($this->automatic, 'activated', true); + $this->assertCount(15, Automatic::getSubscribedEvents()); NSA::setProperty($this->automatic, 'activated', false); @@ -493,6 +495,8 @@ public function testExecuteAutoScriptsWithNumericArray(): void public function testExecuteAutoScriptsWithoutScripts(): void { + \putenv('COMPOSER=' . __DIR__ . '/Fixture/composer-empty-scripts.json'); + $eventMock = $this->mock(Event::class); $eventMock->shouldReceive('stopPropagation') ->never(); @@ -509,6 +513,9 @@ public function testExecuteAutoScriptsWithoutScripts(): void $this->automatic->setContainer($containerMock); $this->automatic->executeAutoScripts($eventMock); + + \putenv('COMPOSER='); + \putenv('COMPOSER'); } public function testPopulateFilesCacheDir(): void @@ -815,6 +822,9 @@ public function testOnPostAutoloadDump(): void { $containerMock = $this->mock(ContainerContract::class); $configuratorMock = $this->mock(ConfiguratorContract::class); + + NSA::setProperty($this->automatic, 'configuratorsLoaded', false); + $configuratorMock->shouldReceive('reset') ->never(); $configuratorMock->shouldReceive('add') diff --git a/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php b/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php index b098dfa0..901bfb19 100644 --- a/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php +++ b/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php @@ -131,4 +131,12 @@ public function testUnconfigure(): void \unlink($composerJsonPath); } + + /** + * {@inheritdoc} + */ + protected function allowMockingNonExistentMethods(bool $allow = false): void + { + parent::allowMockingNonExistentMethods(true); + } } diff --git a/tests/Automatic/Fixture/composer-empty-scripts.json b/tests/Automatic/Fixture/composer-empty-scripts.json new file mode 100644 index 00000000..aa93a57d --- /dev/null +++ b/tests/Automatic/Fixture/composer-empty-scripts.json @@ -0,0 +1,12 @@ +{ + "name": "narrowspark/automatic", + "type": "composer-plugin", + "description": "Composer plugin for automatically project configuration and creation.", + "license": "MIT", + "config": { + "optimize-autoloader": true, + "preferred-install": "dist" + }, + "scripts": { + } +} From d42fee3716fb4b7fdbb12e24f99848b13b852a53 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 11 Aug 2019 01:39:03 +0200 Subject: [PATCH 08/10] fix: fixed infection configuration --- .travis.yml | 2 +- tests/Common/PathTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index aed3358c..66da8038 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,7 +80,7 @@ jobs: php: 7.2 env: REMOVE_XDEBUG=true SETUP=high COMPOSER_VERSION=1.9.0 script: - - ulimit -n 4096 && phpdbg -qrr ./vendor/bin/infection -vvv --test-framework-options='--testsuite=unit' --min-msi=48 --min-covered-msi=70 + - ulimit -n 4096 && phpdbg -qrr ./vendor/bin/infection -vvv --min-msi=40 --min-covered-msi=60 - stage: Coverage php: 7.2 diff --git a/tests/Common/PathTest.php b/tests/Common/PathTest.php index c8b6414f..9f598ee0 100644 --- a/tests/Common/PathTest.php +++ b/tests/Common/PathTest.php @@ -66,9 +66,9 @@ public function providePathsForConcatenation(): array return [ [__DIR__, 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', __DIR__ . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], [__DIR__, \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', __DIR__ . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], - ['', 'foo/bar.txt', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + ['', 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], ['', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], - ['.', 'foo/bar.txt', '.' . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], + ['.', 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt', '.' . \DIRECTORY_SEPARATOR . 'foo' . \DIRECTORY_SEPARATOR . 'bar.txt'], ]; } } From ddadef454d56921b08dbdbccfd1788b7bf770325 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 11 Aug 2019 09:28:03 +0200 Subject: [PATCH 09/10] test: Add test for InstallationManager uninstall function --- composer.json | 6 +-- .../Installer/InstallationManager.php | 4 +- .../Installer/AbstractInstallationManager.php | 2 +- .../Installer/InstallationManagerTest.php | 40 +++++++++++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 4f0ef19b..ded3eb69 100644 --- a/composer.json +++ b/composer.json @@ -84,10 +84,8 @@ "infection": "infection", "test-common": "phpunit --testsuite=\"Narrowspark Automatic Common Test Suite\"", "test-automatic": "phpunit --testsuite=\"Narrowspark Automatic Test Suite\"", - "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend", - "auto-scripts": { - - } + "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend", + "auto-scripts": [] }, "support": { "issues": "https://github.com/narrowspark/automatic/issues", diff --git a/src/Automatic/Installer/InstallationManager.php b/src/Automatic/Installer/InstallationManager.php index 41ae45bc..5219642f 100644 --- a/src/Automatic/Installer/InstallationManager.php +++ b/src/Automatic/Installer/InstallationManager.php @@ -46,7 +46,7 @@ public function install(array $requires, array $devRequires = []): void } /** - * Install required and required-dev packages. + * Uninstall required and required-dev packages. * * @param \Narrowspark\Automatic\Common\Contract\Package[] $requires * @param \Narrowspark\Automatic\Common\Contract\Package[] $devRequires @@ -57,7 +57,7 @@ public function install(array $requires, array $devRequires = []): void * * @return void */ - public function uninstall(array $requires, array $devRequires): void + public function uninstall(array $requires, array $devRequires = []): void { $requires = $this->preparePackagesToUninstall($requires); $devRequires = $this->preparePackagesToUninstall($devRequires); diff --git a/src/Common/Installer/AbstractInstallationManager.php b/src/Common/Installer/AbstractInstallationManager.php index c644766c..3eea974d 100644 --- a/src/Common/Installer/AbstractInstallationManager.php +++ b/src/Common/Installer/AbstractInstallationManager.php @@ -155,7 +155,7 @@ protected function findBestVersionForPackage(string $name): string if ($package === false) { throw new InvalidArgumentException(\sprintf( - 'Could not find package %s at any version for your minimum-stability (%s).' + 'Could not find package [%s] at any version for your minimum-stability [%s].' . ' Check the package spelling or your minimum-stability.', $name, $this->stability diff --git a/tests/Automatic/Installer/InstallationManagerTest.php b/tests/Automatic/Installer/InstallationManagerTest.php index 9c676d89..a29b3c6f 100644 --- a/tests/Automatic/Installer/InstallationManagerTest.php +++ b/tests/Automatic/Installer/InstallationManagerTest.php @@ -281,6 +281,46 @@ public function testInstallWithRequireAndPackageVersion(): void \putenv('COMPOSER'); } + public function testUninstallWithoutRequireAndRequireDev(): void + { + $path = __DIR__ . '/Fixture/composer.json'; + $dirPath = \dirname($path); + + @\mkdir($dirPath); + @\file_put_contents($path, \json_encode(['require' => [], 'require-dev' => []])); + \putenv('COMPOSER=' . $path); + + $this->ioMock->shouldReceive('writeError') + ->atLeast() + ->once(); + + $this->rootPackageMock->shouldReceive('getRequires') + ->once() + ->andReturn([]); + $this->rootPackageMock->shouldReceive('getDevRequires') + ->once() + ->andReturn([]); + $this->rootPackageMock->shouldReceive('setRequires') + ->once() + ->with([]); + $this->rootPackageMock->shouldReceive('setDevRequires') + ->once() + ->with([]); + + $this->localRepositoryMock->shouldReceive('getPackages') + ->andReturn([]); + + $manager = new InstallationManager($this->composerMock, $this->ioMock, $this->inputMock); + + $manager->uninstall([]); + + $this->delete($dirPath); + \rmdir($dirPath); + + \putenv('COMPOSER='); + \putenv('COMPOSER'); + } + /** * {@inheritdoc} */ From acd562d7d6aa3c79061949876ea5dd1ee6add3f0 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 11 Aug 2019 09:46:15 +0200 Subject: [PATCH 10/10] style: remove auto-scripts from main composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ded3eb69..4a7b7229 100644 --- a/composer.json +++ b/composer.json @@ -84,8 +84,7 @@ "infection": "infection", "test-common": "phpunit --testsuite=\"Narrowspark Automatic Common Test Suite\"", "test-automatic": "phpunit --testsuite=\"Narrowspark Automatic Test Suite\"", - "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend", - "auto-scripts": [] + "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend" }, "support": { "issues": "https://github.com/narrowspark/automatic/issues",