diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..677e36e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2cf86dc..89c8d08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,10 @@ name: Tests -on: [push, pull_request] + +on: + pull_request: ~ + push: + branches: + - master jobs: @@ -7,10 +12,8 @@ jobs: name: Build runs-on: ubuntu-latest strategy: - max-parallel: 10 matrix: php: ['7.3', '7.4'] - sf_version: ['4.4.*', '5.0.*'] steps: - name: Set up PHP @@ -24,35 +27,7 @@ jobs: uses: actions/checkout@v2 - name: Download dependencies - env: - SYMFONY_REQUIRE: ${{ matrix.sf_version }} - run: | - composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable + run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable - name: Run tests run: ./vendor/bin/simple-phpunit - - lowest: - name: Lowest deps - runs-on: ubuntu-latest - steps: - - name: Set up PHP - uses: shivammathur/setup-php@2.1.0 - with: - php-version: 7.3 - coverage: pcov - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Download dependencies - run: | - composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable --prefer-lowest - - - name: Run tests - env: - SYMFONY_DEPRECATIONS_HELPER: "max[self]=0" - run: | - ./vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=coverage.xml - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.xml \ No newline at end of file diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 7df3778..c35f0f1 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,27 +1,56 @@ -on: [push, pull_request] name: Static analysis +on: + pull_request: ~ + push: + branches: + - master + jobs: phpstan: name: PHPStan runs-on: ubuntu-latest + steps: + - name: Set up PHP + uses: shivammathur/setup-php@2.7.0 + with: + php-version: '7.4' + coverage: none + - name: Checkout code uses: actions/checkout@v2 + - name: Download dependencies + run: composer install --no-interaction --optimize-autoloader + - name: PHPStan - uses: docker://oskarstark/phpstan-ga - env: - REQUIRE_DEV: true + uses: docker://oskarstark/phpstan-ga:0.12.48 with: + entrypoint: /composer/vendor/bin/phpstan args: analyze --no-progress php-cs-fixer: name: PHP-CS-Fixer runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 + - name: PHP-CS-Fixer - uses: docker://oskarstark/php-cs-fixer-ga + uses: docker://oskarstark/php-cs-fixer-ga:2.16.4 with: args: --dry-run --diff-format udiff + + psalm: + name: Psalm + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Psalm + uses: docker://vimeo/psalm-github-actions:3.17.2 + with: + args: --no-progress --show-info=false --stats diff --git a/Readme.md b/Readme.md index 3a2eff1..9c38edb 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,7 @@ # Find reviewers ``` -./git-reviewer.php --env=dev find 106 /Users/tobias/Workspace/PHPStorm/carsonbot --ignore-path "config/*" --ignore-path .env --pretty-print +./git-reviewer.php find 106 /Users/tobias/Workspace/PHPStorm/carsonbot --ignore-path "config/*" --ignore-path .env --pretty-print ``` ```json diff --git a/composer.json b/composer.json index d4216fa..022bb5b 100644 --- a/composer.json +++ b/composer.json @@ -32,5 +32,8 @@ "psr-4": { "Tests\\Nyholm\\GitReviewer\\": "tests/" } + }, + "require-dev": { + "symfony/phpunit-bridge": "^5.1" } } diff --git a/config/packages/cache.yaml b/config/packages/cache.yaml index 3f67b98..aeccb80 100644 --- a/config/packages/cache.yaml +++ b/config/packages/cache.yaml @@ -6,5 +6,5 @@ services: arguments: - 'git-reviewer' - 0 - - '%kernel.cache_dir%' + - '%kernel.cache_dir%/cache' diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9631d44..6b029d3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1 +1,12 @@ parameters: + ignoreErrors: + - + message: "#^Instantiated class CachedContainer not found\\.$#" + count: 1 + path: src/Kernel.php + + - + message: "#^Property Nyholm\\\\GitReviewer\\\\Kernel\\:\\:\\$container \\(Symfony\\\\Component\\\\DependencyInjection\\\\Container\\) does not accept CachedContainer\\.$#" + count: 1 + path: src/Kernel.php + diff --git a/psalm.baseline.xml b/psalm.baseline.xml new file mode 100644 index 0000000..c159e24 --- /dev/null +++ b/psalm.baseline.xml @@ -0,0 +1,8 @@ + + + + + new \CachedContainer() + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..e044bd6 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/Application.php b/src/Application.php index 0a26ef2..9e63c57 100644 --- a/src/Application.php +++ b/src/Application.php @@ -25,7 +25,6 @@ public function __construct(Kernel $kernel) $inputDefinition = $this->getDefinition(); $inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'prod')); - } /** diff --git a/src/Command/CacheClearCommand.php b/src/Command/CacheClearCommand.php index e65e57b..e208301 100644 --- a/src/Command/CacheClearCommand.php +++ b/src/Command/CacheClearCommand.php @@ -36,4 +36,4 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } -} \ No newline at end of file +} diff --git a/src/Command/FindCommand.php b/src/Command/FindCommand.php index ca12bbf..bd01601 100644 --- a/src/Command/FindCommand.php +++ b/src/Command/FindCommand.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Filesystem\Filesystem; class FindCommand extends Command { @@ -23,7 +22,6 @@ class FindCommand extends Command private $contributorProvider; private $usernameProvider; - public function __construct(RepositoryProvider $repositoryProvider, ChangeSetProvider $changeSetProvider, ContributorProvider $contributorProvider, GithubUsernameProvider $usernameProvider) { parent::__construct(); @@ -55,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // run git blame on paths in workspace $after = $input->getOption('after'); - if ($after === null) { + if (null === $after) { $after = '2010-01-01'; } @@ -67,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $contributors[$key]['username'] = $this->usernameProvider->findUsername($c['email'], $c['name']); } } - $x =2; + $x = 2; if ($input->getOption('pretty-print')) { $output->writeln(json_encode($contributors, JSON_PRETTY_PRINT)); @@ -77,4 +75,4 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } -} \ No newline at end of file +} diff --git a/src/Kernel.php b/src/Kernel.php index 9f490eb..24d3295 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -14,7 +14,6 @@ use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -use Symfony\Component\DependencyInjection\Loader\ClosureLoader; use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -35,7 +34,7 @@ class Kernel public function __construct(string $env) { - $this->debug = $env !== 'prod'; + $this->debug = 'prod' !== $env; $this->env = $env; } @@ -117,6 +116,4 @@ public function getEnvironment(): string { return $this->env; } - - } diff --git a/src/Service/ChangeSetProvider.php b/src/Service/ChangeSetProvider.php index 7523792..1d3e8b4 100644 --- a/src/Service/ChangeSetProvider.php +++ b/src/Service/ChangeSetProvider.php @@ -2,10 +2,8 @@ declare(strict_types=1); - namespace Nyholm\GitReviewer\Service; - use Github\Client; use Nyholm\GitReviewer\Model\Repository; use Symfony\Component\Process\Process; @@ -17,15 +15,11 @@ class ChangeSetProvider */ private $github; - /** - * @param Client $github - */ public function __construct(Client $github) { $this->github = $github; } - public function getChangedFiles(Repository $repository, int $number, array $ignoredPaths): array { $pr = $this->github->pullRequest()->show($repository->getUser(), $repository->getName(), $number); @@ -88,7 +82,6 @@ private function validFile(string $path, array $ignoredFiles, $ignoredPatterns): return false; } - foreach ($ignoredPatterns as $pattern) { if (preg_match($pattern, $path)) { return false; diff --git a/src/Service/ContributorProvider.php b/src/Service/ContributorProvider.php index 85a505c..c06e1d7 100644 --- a/src/Service/ContributorProvider.php +++ b/src/Service/ContributorProvider.php @@ -2,10 +2,8 @@ declare(strict_types=1); - namespace Nyholm\GitReviewer\Service; - use Nyholm\GitReviewer\Model\Repository; use Symfony\Component\Process\Process; @@ -23,7 +21,7 @@ public function getContributors(Repository $repository, array $files, \DateTimeI $authors = array_values($authors); usort($authors, function ($a, $b) { - return $b['contributions'] - $a['contributions']; + return $b['contributions'] - $a['contributions']; }); return $authors; @@ -54,8 +52,8 @@ private function parseAuthors(array &$authors, string $output, int $after) 'contributions' => 1, ]; } else { - $authors[$matches[2][$i]]['contributions']++; + ++$authors[$matches[2][$i]]['contributions']; } } } -} \ No newline at end of file +} diff --git a/src/Service/GithubUsernameProvider.php b/src/Service/GithubUsernameProvider.php index f6270b4..425188b 100644 --- a/src/Service/GithubUsernameProvider.php +++ b/src/Service/GithubUsernameProvider.php @@ -2,10 +2,8 @@ declare(strict_types=1); - namespace Nyholm\GitReviewer\Service; - use Github\Client; use Symfony\Contracts\Cache\CacheInterface; use Symfony\Contracts\Cache\ItemInterface; @@ -18,9 +16,6 @@ class GithubUsernameProvider private $github; private $cache; - /** - * @param Client $github - */ public function __construct(Client $github, CacheInterface $cache) { $this->github = $github; @@ -30,16 +25,19 @@ public function __construct(Client $github, CacheInterface $cache) public function findUsername(string $email, string $name): ?string { $key = 'user_'.sha1($email.$name); + return $this->cache->get($key, function (ItemInterface $item) use ($email, $name) { $byEmail = $this->github->search()->users($email.' in:email type:users '); - if ($byEmail['total_count'] === 1) { + if (1 === $byEmail['total_count']) { $item->expiresAfter(31536000); + return $byEmail['items'][0]['login']; } $byName = $this->github->search()->users('type:users fullname:'.sprintf('"%s"', $name)); - if ($byName['total_count'] === 1) { + if (1 === $byName['total_count']) { $item->expiresAfter(31536000); + return $byName['items'][0]['login']; } @@ -48,4 +46,4 @@ public function findUsername(string $email, string $name): ?string return null; }); } -} \ No newline at end of file +} diff --git a/src/Service/RepositoryProvider.php b/src/Service/RepositoryProvider.php index 33eb84f..efb69ff 100644 --- a/src/Service/RepositoryProvider.php +++ b/src/Service/RepositoryProvider.php @@ -2,14 +2,14 @@ declare(strict_types=1); - namespace Nyholm\GitReviewer\Service; use Nyholm\GitReviewer\Model\Repository; use Symfony\Component\Process\Process; /** - * Find repository from git root + * Find repository from git root. + * * @author Tobias Nyholm */ class RepositoryProvider @@ -25,4 +25,4 @@ public function find(string $workspace): Repository return new Repository($matches[1], $matches[2], $workspace); } -} \ No newline at end of file +} diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..e69de29