Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Rector + PHP CS Fixer

on:
pull_request:
paths:
- 'src/**'
- 'tests/**'
- 'rector.php'
- '.php-cs-fixer.dist.php'
- 'composer.json'
- '.github/workflows/rector-cs.yml'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector-cs:
permissions:
contents: write # Required to commit formatting fixes back to the PR
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
with:
php: '8.1'
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return ConfigBuilder::build()
->setCacheFile(__DIR__ . '/runtime/.php-cs-fixer.cache')
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
86 changes: 0 additions & 86 deletions .styleci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.2.1 under development

- no changes in this release.
- Enh #85: Explicitly import functions and constants in "use" section (@vjik)

## 1.2.0 April 02, 2026

Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
"yiisoft/files": "^1.0.2 || ^2.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.95",
"phpunit/phpunit": "^10.5.47",
"rector/rector": "^2.5",
"roave/infection-static-analysis-plugin": "^1.35",
"vimeo/psalm": "^5.26.1 || ^6.12"
"vimeo/psalm": "^5.26.1 || ^6.12",
"yiisoft/code-style": "^1.1"
},
"autoload": {
"psr-4": {
Expand All @@ -45,7 +48,9 @@
}
},
"scripts": {
"cs-fix": "php-cs-fixer fix",
"phan": "phan --progress-bar -o analysis.txt",
"rector": "rector",
"test": "phpunit --testdox --no-interaction"
},
"config": {
Expand Down
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Yiisoft\CodeStyle\Rector\SetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets(php81: true)
->withSets([
SetList::YII_CORE,
]);
2 changes: 2 additions & 0 deletions runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
10 changes: 7 additions & 3 deletions src/ClassCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
use RuntimeException;
use Yiisoft\Files\FileHelper;

use function count;

use const DIRECTORY_SEPARATOR;
use const LOCK_EX;

/**
* @internal
*
Expand All @@ -21,9 +26,8 @@ public function __construct(
* @var string Base directory for working with cache. It will be created automatically if it does not exist
* ({@see getClassPath()}).
*/
private string $cachePath
) {
}
private string $cachePath,
) {}

/**
* Writes proxy class contents to a file in {@see getClassPath()}.
Expand Down
8 changes: 4 additions & 4 deletions src/ClassConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ private function getMethodModifiers(ReflectionClass $class, ReflectionMethod $me
return array_values(
array_filter(
$modifiers,
static fn (string $modifier) => $modifier !== 'abstract'
)
static fn(string $modifier) => $modifier !== 'abstract',
),
);
}

Expand Down Expand Up @@ -241,7 +241,7 @@ function (ReflectionNamedType|ReflectionIntersectionType $subType) use ($declari
$name = $subType->getName();
return ($declaringClassName !== null && $name === $declaringClassName) ? 'self' : $name;
},
$type->getTypes()
$type->getTypes(),
);

return implode('|', $types);
Expand All @@ -258,7 +258,7 @@ function (ReflectionNamedType|ReflectionUnionType $subType) use ($declaringClass
$name = $subType->getName();
return ($declaringClassName !== null && $name === $declaringClassName) ? 'self' : $name;
},
$type->getTypes()
$type->getTypes(),
);

return implode('&', $types);
Expand Down
3 changes: 1 addition & 2 deletions src/Config/ClassConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ public function __construct(
* @psalm-var array<string, MethodConfig>
*/
public array $methods,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Config/MethodConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function __construct(
* @var TypeConfig|null Return type config. `null` means no return type specified.
*/
public ?TypeConfig $returnType,
) {
}
) {}

/**
* Whether a method has return type.
Expand Down
3 changes: 1 addition & 2 deletions src/Config/ParameterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function __construct(
* when {@see $isDefaultValueAvailable} is `false`).
*/
public mixed $defaultValue,
) {
}
) {}

/**
* Whether a parameter has type.
Expand Down
3 changes: 1 addition & 2 deletions src/Config/TypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ public function __construct(
* @link https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.nullable-types
*/
public bool $allowsNull,
) {
}
) {}
}
11 changes: 6 additions & 5 deletions src/ObjectProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Throwable;

use function is_object;

/**
* Base proxy class for objects to use in {@see ProxyManager}. A concrete implementation can be provided too.
* @psalm-suppress ClassMustBeFinal
Expand All @@ -18,9 +20,8 @@ public function __construct(
/**
* @var object An instance of the class for proxying method calls.
*/
private object $instance
) {
}
private object $instance,
) {}

/**
* Gets instance.
Expand Down Expand Up @@ -76,7 +77,7 @@ protected function afterCall(
string $methodName,
array $arguments,
mixed $result,
float $timeStart
float $timeStart,
): mixed {
return $result;
}
Expand Down Expand Up @@ -120,7 +121,7 @@ private function callInternal(string $methodName, array $arguments): mixed
*/
private function processResult(mixed $result): mixed
{
if (is_object($result) && get_class($result) === get_class($this->instance)) {
if (is_object($result) && $result::class === $this->instance::class) {
$result = $this->getNewStaticInstance($result);
}

Expand Down
11 changes: 5 additions & 6 deletions src/ProxyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

final class ProxyManager
{
/**
* A suffix appended to proxy class names / files.
*/
public const PROXY_SUFFIX = 'Proxy';
/**
* @var ClassRenderer A class renderer dependency.
*/
Expand All @@ -22,18 +26,13 @@
*/
private ?ClassCache $classCache;

/**
* A suffix appended to proxy class names / files.
*/
public const PROXY_SUFFIX = 'Proxy';

/**
* @param string|null $cachePath Cache path, optional, {@see ClassCache::$cachePath}. Pass `null` to disable
* caching.
*/
public function __construct(?string $cachePath = null)
{
$this->classCache = ($cachePath !== null && $cachePath !== '') ? new ClassCache($cachePath) : null;

Check warning on line 35 in src/ProxyManager.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "NotIdentical": --- Original +++ New @@ @@ */ public function __construct(?string $cachePath = null) { - $this->classCache = $cachePath !== null && $cachePath !== '' ? new ClassCache($cachePath) : null; + $this->classCache = $cachePath !== null && $cachePath === '' ? new ClassCache($cachePath) : null; $this->classRenderer = new ClassRenderer(); $this->classConfigFactory = new ClassConfigFactory(); }
$this->classRenderer = new ClassRenderer();
$this->classConfigFactory = new ClassConfigFactory();
}
Expand All @@ -56,7 +55,7 @@
public function createObjectProxy(
string $baseStructure,
string $parentProxyClass,
array $proxyConstructorArguments
array $proxyConstructorArguments,
): ObjectProxy {
$className = $baseStructure . self::PROXY_SUFFIX;
/** @psalm-var class-string $shortClassName */
Expand Down
4 changes: 3 additions & 1 deletion tests/ClassCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use function sys_get_temp_dir;

use const DIRECTORY_SEPARATOR;

class ClassCacheTest extends TestCase
{
public function tearDown(): void
Expand Down Expand Up @@ -61,7 +63,7 @@ class Node

$expectedClassPath = implode(
DIRECTORY_SEPARATOR,
[sys_get_temp_dir(), 'Yiisoft', 'Proxy', 'Tests', 'Stub', 'Node.MyProxy.php']
[sys_get_temp_dir(), 'Yiisoft', 'Proxy', 'Tests', 'Stub', 'Node.MyProxy.php'],
);
$actualClassPath = $cache->getClassPath(Node::class, MyProxy::class);
$this->assertEquals($expectedClassPath, $actualClassPath);
Expand Down
Loading
Loading