Skip to content

Commit

Permalink
Merge pull request #789 from veewee/standalone-tools
Browse files Browse the repository at this point in the history
Standalone tools
  • Loading branch information
veewee authored Aug 3, 2020
2 parents 5e43284 + 625f9f1 commit a0a9a33
Show file tree
Hide file tree
Showing 103 changed files with 373 additions and 138 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 7.2
- 7.3
- 7.4
- nightly
Expand Down Expand Up @@ -37,7 +36,7 @@ install:
- travis_retry composer update --no-progress --profile --no-scripts --no-suggest $DEPENDENCIES

script:
- bin/grumphp run
- bin/grumphp run --no-interaction

notifications:
irc:
Expand Down
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ platform:

environment:
matrix:
- dependencies: highest
php_version: 7.2
- dependencies: highest
php_version: 7.3
- dependencies: highest
Expand Down Expand Up @@ -71,4 +69,4 @@ install:

test_script:
- ps: cd $Env:project_directory
- php ./bin/grumphp run
- php ./bin/grumphp run --testsuite=windows --no-interaction
14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.3",
"ext-json": "*",
"amphp/amp": "^2.4",
"amphp/parallel": "^1.4",
"amphp/parallel-functions": "^0.1.3",
"composer-plugin-api": "~1.0 || ~2.0",
"doctrine/collections": "~1.2",
"doctrine/collections": "^1.6.7",
"gitonomy/gitlib": "^1.0.3",
"monolog/monolog": "~1.16 || ^2.0",
"opis/closure": "^3.5",
Expand All @@ -38,15 +38,13 @@
"symfony/yaml": "~4.4 || ~5.0"
},
"require-dev": {
"brianium/paratest": "~3.1 || dev-master",
"brianium/paratest": "^4.1",
"composer/composer": "~1.9 || ^2.0@dev",
"ergebnis/composer-normalize": "~2.1",
"jakub-onderka/php-parallel-lint": "~1.0",
"nikic/php-parser": "~4.0",
"phpspec/phpspec": "~6.1",
"phpunit/phpunit": "^7.5.17",
"sensiolabs/security-checker": "~6.0",
"squizlabs/php_codesniffer": "~3.5"
"phpspec/phpspec": "^6.2",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.2"
},
"suggest": {
"atoum/atoum": "Lets GrumPHP run your unit tests.",
Expand Down
11 changes: 7 additions & 4 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ grumphp:
testsuite: Unit
composer:
no_check_lock: true
composer_normalize: ~
composer_normalize:
use_standalone: true
yamllint:
parse_custom_tags: true
ignore_patterns:
Expand All @@ -35,11 +36,13 @@ grumphp:
functional: true
psalm:
show_info: true
metadata:
blocking: false
testsuites:
git_pre_commit:
tasks: [phpcs, phpspec, phpunit, composer, composer_normalize, yamllint, phplint, phpparser]
tasks: [phpcs, phpspec, phpunit, composer, composer_normalize, yamllint, phplint, phpparser, psalm]
# Dont run psalm on windows for now. There is a known issue with the windows phar:
# https://github.com/vimeo/psalm/issues/2858
windows:
tasks: [phpcs, phpspec, phpunit, composer, composer_normalize, yamllint, phplint, phpparser, paratest]
environment:
paths:
- tools
3 changes: 3 additions & 0 deletions phive.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="psalm" version="^3.12.2" installed="3.12.2" location="./tools/psalm" copy="true"/>
<phar name="phpcs" version="^3.5.5" installed="3.5.5" location="./tools/phpcs" copy="true"/>
<phar name="phpcbf" version="^3.5.5" installed="3.5.5" location="./tools/phpcbf" copy="true"/>
<phar name="composer-normalize" version="^2.6.1" installed="2.6.1" location="./tools/composer-normalize" copy="true"/>
</phive>
5 changes: 4 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
totallyTyped="true"
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -12,6 +12,9 @@
<ignoreFiles>
<directory name="src/Test" />
<directory name="vendor" />
<directory name="test" />
<directory name="spec" />
<file name="src/Parser/Php/Visitor/AbstractVisitor.php" />
</ignoreFiles>
</projectFiles>

Expand Down
21 changes: 18 additions & 3 deletions src/Collection/FilesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Symfony\Component\Finder\SplFileInfo as SymfonySplFileInfo;
use Traversable;

/**
* @extends ArrayCollection<int, \SplFileInfo>
*/
class FilesCollection extends ArrayCollection implements \Serializable
{
/**
Expand Down Expand Up @@ -170,6 +173,8 @@ public function date(string $date): self
*
*
* @see CustomFilterIterator
*
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function filter(Closure $closure): self
{
Expand All @@ -178,7 +183,7 @@ public function filter(Closure $closure): self
return new self(iterator_to_array($filter));
}

public function filterByFileList(Traversable $fileList): self
public function filterByFileList(Traversable $fileList): FilesCollection
{
$allowedFiles = array_map(function (SplFileInfo $file) {
return $file->getPathname();
Expand All @@ -189,7 +194,7 @@ public function filterByFileList(Traversable $fileList): self
});
}

public function ensureFiles(self $files): self
public function ensureFiles(self $files): FilesCollection
{
$newFiles = new self($this->toArray());

Expand All @@ -202,7 +207,7 @@ public function ensureFiles(self $files): self
return $newFiles;
}

public function ignoreSymlinks(): self
public function ignoreSymlinks(): FilesCollection
{
return $this->filter(function (SplFileInfo $file) {
return !$file->isLink();
Expand Down Expand Up @@ -236,4 +241,14 @@ public function unserialize($serialized): void
$this->add(new SymfonySplFileInfo($file, dirname($file), $file));
}
}

/**
* Help Psalm out a bit:
*
* @return \ArrayIterator<int, SplFileInfo>
*/
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->toArray());
}
}
3 changes: 3 additions & 0 deletions src/Collection/LintErrorsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Doctrine\Common\Collections\ArrayCollection;

/**
* @extends ArrayCollection<int, \GrumPHP\Linter\LintError>
*/
class LintErrorsCollection extends ArrayCollection
{
public function __toString(): string
Expand Down
3 changes: 3 additions & 0 deletions src/Collection/ParseErrorsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Doctrine\Common\Collections\ArrayCollection;

/**
* @extends ArrayCollection<int, \GrumPHP\Parser\ParseError>
*/
class ParseErrorsCollection extends ArrayCollection
{
public function __toString(): string
Expand Down
13 changes: 11 additions & 2 deletions src/Collection/ProcessArgumentsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
use Doctrine\Common\Collections\ArrayCollection;
use GrumPHP\Exception\InvalidArgumentException;

/**
* @extends ArrayCollection<int, string>
*/
class ProcessArgumentsCollection extends ArrayCollection
{
public static function forExecutable(string $executable): self
{
return new self([$executable]);
}

/**
* @param mixed $value
*/
public function addOptionalArgument(string $argument, $value = null): void
{
if (!$value) {
Expand All @@ -23,14 +29,17 @@ public function addOptionalArgument(string $argument, $value = null): void
$this->add(sprintf($argument, $value));
}

/**
* @param string|null|int $value
*/
public function addOptionalArgumentWithSeparatedValue(string $argument, $value = null): void
{
if (!$value) {
return;
}

$this->add($argument);
$this->add($value);
$this->add((string) $value);
}

public function addOptionalCommaSeparatedArgument(string $argument, array $values, string $delimiter = ','): void
Expand Down Expand Up @@ -137,7 +146,7 @@ public function addOptionalIntegerArgument(string $argument, ?int $value): void
* @param string $argument
* @param mixed $value
*/
public function addOptionalMixedArgument(string $argument, $value)
public function addOptionalMixedArgument(string $argument, $value): void
{
if (null === $value) {
return;
Expand Down
5 changes: 2 additions & 3 deletions src/Collection/TaskResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use GrumPHP\Runner\TaskResultInterface;

/**
* @template TResult
* @extends ArrayCollection<int, TResult|TaskResultInterface>
* @extends ArrayCollection<int, TaskResultInterface>
*/
class TaskResultCollection extends ArrayCollection
{
Expand Down Expand Up @@ -44,7 +43,7 @@ public function getResultCode(): int

public function filterByResultCode(int $resultCode): self
{
return $this->filter(function (TaskResultInterface $taskResult) use ($resultCode) {
return $this->filter(function (TaskResultInterface $taskResult) use ($resultCode): bool {
return $resultCode === $taskResult->getResultCode();
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/Collection/TasksCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use GrumPHP\TestSuite\TestSuiteInterface;
use SplPriorityQueue;

/**
* @extends ArrayCollection<int, TaskInterface>
*/
class TasksCollection extends ArrayCollection
{
public function filterByContext(ContextInterface $context): self
Expand Down
7 changes: 5 additions & 2 deletions src/Collection/TestSuiteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
use GrumPHP\Exception\InvalidArgumentException;
use GrumPHP\TestSuite\TestSuiteInterface;

/**
* @extends ArrayCollection<string, TestSuiteInterface>
*/
class TestSuiteCollection extends ArrayCollection
{
public function getRequired(string $name): TestSuiteInterface
{
if (!$this->containsKey($name)) {
if (!$result = $this->get($name)) {
throw InvalidArgumentException::unknownTestSuite($name);
}

return $this->get($name);
return $result;
}

public function getOptional(string $name): ?TestSuiteInterface
Expand Down
11 changes: 7 additions & 4 deletions src/Composer/GrumPHPPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Composer\Script\Event;
use Composer\Script\ScriptEvents;

/**
* @psalm-suppress MissingConstructor
*/
class GrumPHPPlugin implements PluginInterface, EventSubscriberInterface
{
private const PACKAGE_NAME = 'phpro/grumphp';
Expand Down Expand Up @@ -68,14 +71,14 @@ public function activate(Composer $composer, IOInterface $io): void
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io)
public function deactivate(Composer $composer, IOInterface $io): void
{
}

/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io)
public function uninstall(Composer $composer, IOInterface $io): void
{
}

Expand Down Expand Up @@ -218,7 +221,7 @@ private function runGrumPhpCommand(string $command): void

// Windows requires double double quotes
// https://bugs.php.net/bug.php?id=49139
$windowsIsInsane = function (string $command) {
$windowsIsInsane = function (string $command): string {
return $this->runsOnWindows() ? '"'.$command.'"' : $command;
};

Expand Down Expand Up @@ -292,7 +295,7 @@ private function ensurePlatformSpecificDirectorySeparator(string $path): string
return str_replace('/', DIRECTORY_SEPARATOR, $path);
}

private function pluginErrored(string $reason)
private function pluginErrored(string $reason): void
{
$this->io->writeError('<fg=red>GrumPHP can not sniff your commits! ('.$reason.')</fg=red>');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Compiler/TaskCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function getTaskTag(array $tag): array
$taskTagResolver->setAllowedTypes('priority', ['int']);
$taskTagResolver->setDefault('task', '');
$taskTagResolver->setDefault('priority', 0);
$taskTagResolver->setNormalizer('task', static function (Options $options, $value) {
$taskTagResolver->setNormalizer('task', static function (Options $options, ?string $value) {
if (!$value && !$options->offsetExists('config')) {
throw new MissingOptionsException('The required option "task" is missing.');
}
Expand All @@ -104,7 +104,7 @@ private function getTaskTag(array $tag): array
$taskTagResolver->setDefined('config');
$taskTagResolver->setNormalizer(
'config',
static function (Options $options, $value) {
static function (Options $options, string $value) {
throw TaskConfigResolverException::deprectatedTask($value);
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getConfigTreeBuilder(): TreeBuilder

// Process timeout (null or float)
$processTimeout = $rootNode->children()->scalarNode('process_timeout')->defaultValue(60.0);
$processTimeout->beforeNormalization()->always(static function ($value): ?float {
$processTimeout->beforeNormalization()->always(static function (?float $value): ?float {
if (null === $value) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Environment/PathsRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static function prependOne(string $path): void
}

$pathStr = self::pathVarName();
$_SERVER[$pathStr] = realpath($path).PATH_SEPARATOR.getenv($pathStr);
$_SERVER[$pathStr] = realpath($path).PATH_SEPARATOR.(string)getenv($pathStr);
putenv($pathStr.'='.$_SERVER[$pathStr]);
}

Expand All @@ -58,7 +58,7 @@ private static function pathContainsDir(string $dir): bool
{
return (bool) preg_match(
'{(^|'.PATH_SEPARATOR.')'.preg_quote($dir).'($|'.PATH_SEPARATOR.')}',
$_SERVER[self::pathVarName()] ?? []
(string) ($_SERVER[self::pathVarName()] ?? '')
);
}
}
2 changes: 1 addition & 1 deletion src/Configuration/Model/EnvConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EnvConfig
/**
* @param list<string> $files
* @param array<string, string> $variables
* @param list<string> $files
* @param list<string> $paths
*/
public function __construct(
array $files,
Expand Down
Loading

0 comments on commit a0a9a33

Please sign in to comment.