Skip to content

Commit

Permalink
Bump to PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 26, 2023
1 parent aef369d commit 7558d0d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 44 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
LevelSetList::UP_TO_PHP_81,
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
]);
};
14 changes: 6 additions & 8 deletions src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@
use function is_string;
use function rtrim;
use function str_replace;
use function strpos;
use function strtolower;
use function substr;
use function substr_count;
use function token_get_all;
use function trim;

final class Analyser
{
private Collector $collector;
private readonly Collector $collector;

private array $classes = [];

Check failure on line 60 in src/Analyser.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property TomasVotruba\Lines\Analyser::$classes type has no value type specified in iterable type array.

Expand Down Expand Up @@ -538,7 +536,7 @@ private function getClassName($namespace, array $tokens, $i)
$className = $namespace . '\\' . $className;
}

return strtolower($className);
return strtolower((string) $className);
}

/**
Expand Down Expand Up @@ -579,7 +577,7 @@ private function isTestClass($className)

// Fallback: Treat the class as a test case class if the name
// of the parent class ends with "TestCase".
return substr((string) $this->classes[$className], -8) === 'testcase';
return str_ends_with((string) $this->classes[$className], 'testcase');
}

/**
Expand All @@ -596,7 +594,7 @@ private function isTestMethod($functionName, $visibility, $static, array $tokens
return false;
}

if (strpos($functionName, 'test') === 0) {
if (str_starts_with($functionName, 'test')) {
return true;
}

Expand All @@ -608,8 +606,8 @@ private function isTestMethod($functionName, $visibility, $static, array $tokens
$currentToken--;
}

return strpos($tokens[$currentToken][1], '@test') !== false ||
strpos($tokens[$currentToken][1], '@scenario') !== false;
return str_contains((string) $tokens[$currentToken][1], '@test') ||
str_contains((string) $tokens[$currentToken][1], '@scenario');
}

/**
Expand Down
49 changes: 18 additions & 31 deletions src/CLI/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,25 @@

final class Arguments
{
/**
* @psalm-var list<string>
*/
private array $directories;

/**
* @psalm-var list<string>
*/
private array $suffixes;

/**
* @psalm-var list<string>
*/
private array $exclude;

private bool $countTests;

private ?string $jsonLogfile = null;

private bool $help;

private bool $version;

public function __construct(array $directories, array $suffixes, array $exclude, bool $countTests, ?string $jsonLogfile, bool $help, bool $version)
public function __construct(
/**
* @psalm-var list<string>
*/
private readonly array $directories,
/**
* @psalm-var list<string>
*/
private readonly array $suffixes,
/**
* @psalm-var list<string>
*/
private readonly array $exclude,
private readonly bool $countTests,
private readonly ?string $jsonLogfile,
private readonly bool $help,
private readonly bool $version
)
{
$this->directories = $directories;
$this->suffixes = $suffixes;
$this->exclude = $exclude;
$this->countTests = $countTests;
$this->jsonLogfile = $jsonLogfile;
$this->help = $help;
$this->version = $version;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getPublisher()
public function addFile($filename): void
{
$this->increment('files');
$this->addUnique('directories', dirname($filename));
$this->addUnique('directories', dirname((string) $filename));
}

public function incrementLines($number): void
Expand Down
4 changes: 2 additions & 2 deletions tests/_files/class_constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class ClassConstants
{
public const IMPLICITLY_PUBLIC_CONSTANT = 'implicitly public';
public const EXPLICITLY_PUBLIC_CONSTANT = 'explicitly public';
final public const IMPLICITLY_PUBLIC_CONSTANT = 'implicitly public';
final public const EXPLICITLY_PUBLIC_CONSTANT = 'explicitly public';
private /* a comment might be here */ const COMMENT_IN_DEFINTION = 'comment in definition';
private const PRIVATE_CONSTANT = 'private';
protected const PROTECTED_CONSTANT = 'protected';
Expand Down
2 changes: 1 addition & 1 deletion tests/_files/source.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class AnAbstractClass
*/
class AClass extends AnAbstractClass implements AnInterface
{
public const A_CLASS_CONSTANT = 'bar';
final public const A_CLASS_CONSTANT = 'bar';

private static array $a = [];

Expand Down

0 comments on commit 7558d0d

Please sign in to comment.