Skip to content

Commit

Permalink
Update dev tools (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Dec 17, 2021
1 parent 031ce49 commit ebadae6
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 205 deletions.
12 changes: 6 additions & 6 deletions .dev-tools/composer.json
@@ -1,18 +1,18 @@
{
"require": {
"php": "^8.0",
"ergebnis/composer-normalize": "^2.16.0",
"ergebnis/composer-normalize": "^2.18.0",
"kubawerlos/composer-smaller-lock": "^1.0.0",
"kubawerlos/php-cs-fixer-config": "^3.4.0",
"maglnet/composer-require-checker": "^3.5.1",
"kubawerlos/php-cs-fixer-config": "^3.5.0",
"maglnet/composer-require-checker": "^4.0.0",
"mi-schi/phpmd-extension": "^4.3.0",
"phpmd/phpmd": "^2.11.0",
"phpmd/phpmd": "^2.11.1",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^1.2.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.1.0",
"squizlabs/php_codesniffer": "^3.6.1",
"vimeo/psalm": "^4.13.1"
"squizlabs/php_codesniffer": "^3.6.2",
"vimeo/psalm": "^4.15.0"
},
"scripts": {
"analyse": [
Expand Down
317 changes: 129 additions & 188 deletions .dev-tools/composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
@@ -1,8 +1,8 @@
{
"name": "kubawerlos/types-checker",
"type": "library",
"description": "A tool to find missing type declarations in PHP 7 code",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Kuba Werłos",
Expand Down
11 changes: 6 additions & 5 deletions src/ClassCollector.php
Expand Up @@ -12,6 +12,7 @@
namespace TypesChecker;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

final class ClassCollector
{
Expand All @@ -23,7 +24,6 @@ final class ClassCollector
*/
public function __construct(array $paths)
{
/** @var array<string> $files */
$files = [];
foreach ($paths as $path) {
$realPath = \realpath($path);
Expand All @@ -35,9 +35,10 @@ public function __construct(array $paths)
->files()
->name('*.php')
->in($realPath);
/** @var SplFileInfo $file */
foreach ($finder as $file) {
/** @var string $path */
$path = $file->getRealPath();
\assert(\is_string($path));
$files[] = $path;
}
} else {
Expand All @@ -52,7 +53,7 @@ public function __construct(array $paths)
}

\spl_autoload_register(function (string $class): void {
if (isset($this->classes[$class])) {
if (\array_key_exists($class, $this->classes)) {
require_once $this->classes[$class];
}
});
Expand All @@ -71,8 +72,8 @@ public function getClasses(): array
*/
private function getClassesForFile(string $path): array
{
/** @var string $content */
$content = \file_get_contents($path);
\assert(\is_string($content));

$tokens = $this->getTokens($content);

Expand All @@ -87,7 +88,7 @@ private function getClassesForFile(string $path): array
while ($i < $count) {
if ($tokens[$i][0] === \T_NAMESPACE) {
$i += 2;
while (isset($tokens[$i]) && \is_array($tokens[$i])) {
while (\array_key_exists($i, $tokens) && \is_array($tokens[$i])) {
if (\in_array($tokens[$i][0], [\T_NS_SEPARATOR, \T_STRING], true)) {
$namespace .= $tokens[$i][1];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CheckCommand.php
Expand Up @@ -37,8 +37,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var array<string> $paths */
$paths = $input->getArgument('path');

/** @var null|string $autoloader */
$autoloader = $input->getOption('autoloader');
\assert($autoloader === null || \is_string($autoloader));
if ($autoloader !== null) {
if (!\file_exists($autoloader)) {
throw new \InvalidArgumentException(\sprintf('File "%s" does not exist.', $autoloader));
Expand All @@ -54,8 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$checker->exclude($name);
}

/** @var bool $skipReturnTypes */
$skipReturnTypes = $input->getOption('skip-return-types');
\assert(\is_bool($skipReturnTypes));
if ($skipReturnTypes) {
$checker->skipReturnTypes();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Report/ClassReport.php
Expand Up @@ -26,7 +26,7 @@ public function __construct(\ReflectionClass $class)

public function addIssue(\ReflectionMethod $method, string $issue): void
{
if (!isset($this->methods[$method->getName()])) {
if (!\array_key_exists($method->getName(), $this->methods)) {
$this->methods[$method->getName()] = new MethodReport($method);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Report/Report.php
Expand Up @@ -82,7 +82,7 @@ public function hasIssues(): bool

private function getClass(\ReflectionClass $class): ClassReport
{
if (!isset($this->classes[$class->getName()])) {
if (!\array_key_exists($class->getName(), $this->classes)) {
$this->classes[$class->getName()] = new ClassReport($class);
}

Expand Down
2 changes: 1 addition & 1 deletion types-checker
Expand Up @@ -15,8 +15,8 @@ $command = new TypesChecker\Command\CheckCommand('check');

$application->add($command);

/** @var string $name */
$name = $command->getName();
assert(is_string($name));

$application->setDefaultCommand($name, true);
$application->run();

0 comments on commit ebadae6

Please sign in to comment.