diff --git a/.travis.yml b/.travis.yml index f02fefcb1..1140053c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,10 +23,15 @@ matrix: - php: 5.6 - php: 7.0 - php: 7.1 + env: PHPSTAN=1 - php: 7.2 + env: PHPSTAN=1 - php: 7.3 + env: PHPSTAN=1 - php: 7.3 - env: deps=high + env: + - deps=high + - PHPSTAN=1 - php: nightly fast_finish: true allow_failures: @@ -58,6 +63,11 @@ before_script: script: # run test suite directories in parallel using GNU parallel - ls -d tests/Composer/Test/* | grep -v TestCase.php | parallel --gnu --keep-order 'echo "Running {} tests"; ./vendor/bin/phpunit -c tests/complete.phpunit.xml --colors=always {} || (echo -e "\e[41mFAILED\e[0m {}" && exit 1);' + # Run PHPStan + - if [[ $PHPSTAN == "1" ]]; then + composer require --dev phpstan/phpstan-shim:^0.11 --ignore-platform-reqs && + vendor/bin/phpstan.phar analyse src tests --configuration=phpstan/config.neon --autoload-file=phpstan/autoload.php; + fi before_deploy: - php -d phar.readonly=0 bin/compile diff --git a/phpstan/autoload.php b/phpstan/autoload.php new file mode 100644 index 000000000..7d1ed7671 --- /dev/null +++ b/phpstan/autoload.php @@ -0,0 +1,5 @@ +pool = new Pool($this->filterRequires); + $pool = new Pool($this->filterRequires); $this->rootAliases = $rootAliases; // TODO do we really want the request here? kind of want a root requirements thingy instead @@ -133,13 +133,13 @@ class PoolBuilder } } - $this->pool->setPackages($this->packages, $this->priorities); + $pool->setPackages($this->packages, $this->priorities); unset($this->aliasMap); unset($this->loadedNames); unset($this->nameConstraints); - return $this->pool; + return $pool; } private function loadPackage(PackageInterface $package, $repoIndex) diff --git a/src/Composer/Downloader/GzipDownloader.php b/src/Composer/Downloader/GzipDownloader.php index 9748b91ac..91be4593d 100644 --- a/src/Composer/Downloader/GzipDownloader.php +++ b/src/Composer/Downloader/GzipDownloader.php @@ -28,6 +28,7 @@ use Composer\IO\IOInterface; */ class GzipDownloader extends ArchiveDownloader { + /** @var ProcessExecutor */ protected $process; public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null) diff --git a/src/Composer/Downloader/RarDownloader.php b/src/Composer/Downloader/RarDownloader.php index 2ebc3bf18..d0fbadcc6 100644 --- a/src/Composer/Downloader/RarDownloader.php +++ b/src/Composer/Downloader/RarDownloader.php @@ -32,6 +32,7 @@ use RarArchive; */ class RarDownloader extends ArchiveDownloader { + /** @var ProcessExecutor */ protected $process; public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null) diff --git a/src/Composer/Downloader/XzDownloader.php b/src/Composer/Downloader/XzDownloader.php index 19e51c321..371ceda1b 100644 --- a/src/Composer/Downloader/XzDownloader.php +++ b/src/Composer/Downloader/XzDownloader.php @@ -28,6 +28,7 @@ use Composer\IO\IOInterface; */ class XzDownloader extends ArchiveDownloader { + /** @var ProcessExecutor */ protected $process; public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null) diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index efa9fc994..bd8d3b499 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -33,7 +33,9 @@ class ZipDownloader extends ArchiveDownloader private static $hasZipArchive; private static $isWindows; + /** @var ProcessExecutor */ protected $process; + /** @var ZipArchive|null */ private $zipArchiveObject; public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null) diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 405d43261..68540581c 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -31,13 +31,21 @@ use Seld\JsonLint\ParsingException; */ class Locker { + /** @var JsonFile */ private $lockFile; + /** @var RepositoryManager */ private $repositoryManager; + /** @var InstallationManager */ private $installationManager; + /** @var string */ private $hash; + /** @var string */ private $contentHash; + /** @var ArrayLoader */ private $loader; + /** @var ArrayDumper */ private $dumper; + /** @var ProcessExecutor */ private $process; private $lockDataCache; diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 1c2fdf986..d655bc080 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -17,6 +17,7 @@ use Composer\Repository\Vcs\HgDriver; use Composer\IO\NullIO; use Composer\Semver\VersionParser as SemverVersionParser; use Composer\Util\Git as GitUtil; +use Composer\Util\HttpDownloader; use Composer\Util\ProcessExecutor; use Composer\Util\Svn as SvnUtil; diff --git a/src/Composer/Util/Bitbucket.php b/src/Composer/Util/Bitbucket.php index d9f569b1b..ea02dfa0b 100644 --- a/src/Composer/Util/Bitbucket.php +++ b/src/Composer/Util/Bitbucket.php @@ -22,11 +22,17 @@ use Composer\Downloader\TransportException; */ class Bitbucket { + /** @var IOInterface */ private $io; + /** @var Config */ private $config; + /** @var ProcessExecutor */ private $process; + /** @var HttpDownloader */ private $httpDownloader; + /** @var array */ private $token = array(); + /** @var int|null */ private $time; const OAUTH2_ACCESS_TOKEN_URL = 'https://bitbucket.org/site/oauth2/access_token'; diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 1903f1c8d..805eda14b 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -23,6 +23,7 @@ use Symfony\Component\Finder\Finder; */ class Filesystem { + /** @var ProcessExecutor */ private $processExecutor; public function __construct(ProcessExecutor $executor = null) @@ -537,6 +538,9 @@ class Filesystem return $size; } + /** + * @return ProcessExecutor + */ protected function getProcess() { return $this->processExecutor; diff --git a/src/Composer/Util/GitHub.php b/src/Composer/Util/GitHub.php index c3046cb77..d6bfb62ca 100644 --- a/src/Composer/Util/GitHub.php +++ b/src/Composer/Util/GitHub.php @@ -22,9 +22,13 @@ use Composer\Downloader\TransportException; */ class GitHub { + /** @var IOInterface */ protected $io; + /** @var Config */ protected $config; + /** @var ProcessExecutor */ protected $process; + /** @var HttpDownloader */ protected $httpDownloader; /** diff --git a/src/Composer/Util/GitLab.php b/src/Composer/Util/GitLab.php index 2a4867954..b2dbf2836 100644 --- a/src/Composer/Util/GitLab.php +++ b/src/Composer/Util/GitLab.php @@ -23,9 +23,13 @@ use Composer\Json\JsonFile; */ class GitLab { + /** @var IOInterface */ protected $io; + /** @var Config */ protected $config; + /** @var ProcessExecutor */ protected $process; + /** @var HttpDownloader */ protected $httpDownloader; /** diff --git a/src/Composer/Util/Loop.php b/src/Composer/Util/Loop.php index 1be7d478b..c50cf4b02 100644 --- a/src/Composer/Util/Loop.php +++ b/src/Composer/Util/Loop.php @@ -20,7 +20,7 @@ use React\Promise\Promise; */ class Loop { - private $io; + private $httpDownloader; public function __construct(HttpDownloader $httpDownloader) { diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index a87bc6d8b..f39c6dd38 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -14,6 +14,7 @@ namespace Composer\Util; use Composer\Composer; use Composer\CaBundle\CaBundle; +use Composer\Downloader\TransportException; use Psr\Log\LoggerInterface; /** diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index 10ea401a8..89c538eab 100644 --- a/tests/Composer/Test/Downloader/FileDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FileDownloaderTest.php @@ -20,6 +20,8 @@ use Composer\Util\Loop; class FileDownloaderTest extends TestCase { + private $httpDownloader; + protected function getDownloader($io = null, $config = null, $eventDispatcher = null, $cache = null, $httpDownloader = null, $filesystem = null) { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index b754af607..e69149271 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -25,7 +25,7 @@ class ZipDownloaderTest extends TestCase * @var string */ private $testDir; - private $prophet; + private $httpDownloader; private $io; private $config; private $package;