Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable PHP 8.4 compat and update #13

Merged
merged 21 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
328f6be
Update CI to include PHP 8.3 and set 8.4 as current stable
koriym Nov 19, 2024
c0e9f0c
Add Match psalm-type definition
koriym Nov 19, 2024
d5c0da5
Update phpstan v2.0
koriym Nov 19, 2024
96945ae
Add bin command and update tool paths in composer.json
koriym Nov 19, 2024
cc380f9
Update GitHub Actions to use newer workflow versions
koriym Nov 19, 2024
466f2e1
Remove redundant is_string check and cast view to string
koriym Nov 19, 2024
d9585e3
Update composer.lock for package adjustments and removals
koriym Nov 19, 2024
2b9038c
Remove maglnet/composer-require-checker and update composer config
koriym Nov 19, 2024
7f2710c
Update doctrine coding standard v12
koriym Nov 19, 2024
e63aaf3
Disable forward-command in composer.json
koriym Nov 19, 2024
48f57d8
Update header function, PHPCS config, and code format
koriym Nov 19, 2024
4b8d836
Remove unnecessary post-install and post-update commands
koriym Nov 19, 2024
cdffcc9
Update CI workflow to use unified PHP versions parameter
koriym Nov 19, 2024
929971a
Disable unused code and baseline entry detection
koriym Nov 19, 2024
c6f2b66
Update CI workflow to use stable PHP versions
koriym Nov 19, 2024
35cb6ee
Enable bin-links in composer.json
koriym Nov 20, 2024
e3a0aeb
Update PHP compatibility version in phpcs.xml
koriym Nov 20, 2024
e4c5fc6
Enable phpcodesniffer plugin in vendor-bin Composer config
koriym Nov 20, 2024
6b81707
Update workflow versions in coding-standards and static-analysis
koriym Nov 20, 2024
6a9cbbe
Ignore code coverage for HTTP response code setting
koriym Nov 20, 2024
4b4f57d
Ensure $view is an instance of Stringable
koriym Nov 20, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@v1
with:
old_stable: '["8.1", "8.2"]'
current_stable: 8.3
old_stable: '["8.1", "8.2", "8.3"]'
current_stable: 8.4
21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,28 @@
"bamarni/composer-bin-plugin": "^1.4"
},
"scripts" :{
"post-install-cmd": ["@composer bin all install --ansi"],
"post-update-cmd": ["@composer bin all update --ansi"],
"bin": "echo 'no bin' installed.",
"test": ["./vendor/bin/phpunit"],
"tests": ["@cs", "@sa", "@test"],
"coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"pcov": ["php -dextension=pcov.so -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"],
"cs": ["./vendor/bin/phpcs"],
"cs-fix": ["./vendor/bin/phpcbf src tests"],
"clean": ["./vendor/bin/phpstan clear-result-cache", "./vendor/bin/psalm --clear-cache", "rm -rf tests/tmp/*.php"],
"sa": ["./vendor/bin/phpstan analyse -c phpstan.neon", "psalm --show-info=true"],
"metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"cs": ["./vendor-bin/tools/vendor/bin/phpcs"],
"cs-fix": ["./vendor-bin/tools/vendor/bin/phpcbf src tests"],
"clean": ["./vendor-bin/tools/vendor/bin/phpstan clear-result-cache", "./vendor-bin/tools/vendor/bin/psalm --clear-cache", "rm -rf tests/tmp/*.php"],
"sa": ["./vendor-bin/tools/vendor/bin/phpstan analyse -c phpstan.neon", "psalm --show-info=true"],
"metrics": ["./vendor-bin/tools/vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["./vendor-bin/tools/vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"]
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
}
}
}
36 changes: 11 additions & 25 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
<?xml version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="bearcs"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor-bin/tools/vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>

<!-- Compatibility with PHP 7.2.0 -->
<config name="php_version" value="70200"/>
<!-- PHP Compatibility -->
<config name="php_version" value="80300"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<!-- Directories to be checked -->
<file>src</file>
<file>tests</file>
<exclude-pattern>*/tests/tmp/*</exclude-pattern>
<exclude-pattern>*/src/Annotation/*</exclude-pattern>
<exclude-pattern>*/tests/header.php</exclude-pattern>
<exclude-pattern>*/tmp/*</exclude-pattern>
<exclude-pattern>*/Fake/*</exclude-pattern>

<!-- PSR12 Coding Standard -->
<rule ref="PSR12"/>

<!-- Doctrine Coding Standard -->
<!-- Based on Doctrine Coding Standard -->
<rule ref="Doctrine">
<!-- Inapplicable for this project -->
<!-- Base -->
<!-- Exclude Rules -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSame"/>
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<!-- /Base -->
<!-- Option -->
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<!-- attribute -->
<exclude name="Squiz.WhiteSpace.FunctionSpacing.Before"/>
<!-- /Option -->
<!-- Exclude Fake files form Doctrine CS -->
<exclude-pattern>*/tests/Fake/*</exclude-pattern>
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint" />
<exclude name="Squiz.NamingConventions.ValidVariableName.NotCamelCaps" />
</rule>

<!-- Additional Rules -->
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
<properties>
Expand All @@ -58,9 +49,6 @@
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<include-pattern>tests/*</include-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1"/>
Expand All @@ -73,6 +61,4 @@
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<exclude-pattern>*/Fake/*</exclude-pattern>
<exclude-pattern>*/tmp/*</exclude-pattern>
</ruleset>
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ parameters:
paths:
- src
- tests
excludePaths:
- 'tests/Fake'
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="false"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
5 changes: 2 additions & 3 deletions src/Annotation/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

use Attribute;
use Ray\Di\Di\Qualifier;
use function is_string;
use function var_dump;

#[Attribute(Attribute::TARGET_METHOD), Qualifier]
#[Attribute(Attribute::TARGET_METHOD)]
#[Qualifier]
final class Stream
{
}
2 changes: 1 addition & 1 deletion src/StreamModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class StreamModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/StreamProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class StreamProvider implements ProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*
* @return resource
*/
Expand Down
6 changes: 3 additions & 3 deletions src/StreamRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ final class StreamRenderer implements RenderInterface

public function __construct(
private readonly RenderInterface $renderer,
private readonly StreamerInterface $streamer
private readonly StreamerInterface $streamer,
) {
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function render(ResourceObject $ro)
{
Expand All @@ -44,7 +44,7 @@ public function render(ResourceObject $ro)
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getView(ResourceObject $ro): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/StreamResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(private readonly StreamerInterface $streamer)
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function __invoke(ResourceObject $resourceObject, array $server): void
{
Expand All @@ -38,7 +38,7 @@ public function __invoke(ResourceObject $resourceObject, array $server): void

// code
if (PHP_SAPI !== 'cli') {
http_response_code($resourceObject->code);
http_response_code($resourceObject->code); // @codeCoverageIgnore
}

// stream body
Expand Down
5 changes: 3 additions & 2 deletions src/StreamTransferInject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace BEAR\Streamer;

use BEAR\Resource\RenderInterface;
use BEAR\Resource\ResourceObject;
use BEAR\Resource\TransferInterface;
use BEAR\Streamer\Annotation\Stream;
use Ray\Di\Di\Inject;
Expand All @@ -14,7 +15,7 @@ trait StreamTransferInject
/** @var TransferInterface */
private $responder;

/** @return static */
/** @return ResourceObject */
#[Inject]
#[Stream]
public function setRenderer(RenderInterface $render)
Expand All @@ -30,7 +31,7 @@ public function setTransfer(TransferInterface $responder): void
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function transfer(TransferInterface $responder, array $server): void
{
Expand Down
5 changes: 3 additions & 2 deletions src/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use const PREG_SET_ORDER;

/** @psalm-type Match = array<int, array<int, string>> */
final class Streamer implements StreamerInterface
{
/** @var array<resource> */
Expand Down Expand Up @@ -47,7 +48,7 @@ public function getStream(string $string)
$hash = array_keys($this->streams);
$regex = sprintf('/(%s)/', implode('|', $hash));
preg_match_all($regex, $string, $match, PREG_SET_ORDER);
/** @var array<int, string> $match */
/** @var Match $match */
$list = $this->collect($match);
$bodies = (array) preg_split($regex, $string);
foreach ($bodies as $body) {
Expand All @@ -64,7 +65,7 @@ public function getStream(string $string)
}

/**
* @param array<int, string> $match
* @param Match $match
*
* @return array<int, string>
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/Resource/Page/StreamArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class StreamArray extends ResourceObject
{
use StreamTransferInject;

public function onGet()
public function onGet(): static
{
$this->body = [
'msg' =>'hello world',
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/Resource/Page/StreamString.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class StreamString extends ResourceObject
/**
* Ignore renderer, just stream $this->body
*/
public function onGet()
public function onGet(): static
{
$this->body = fopen(__DIR__ . '/message.txt', 'r');
koriym marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/Resource/Page/TextArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TextArray extends ResourceObject
{
public function onGet()
public function onGet(): static
{
$this->body =[
'greeting' => 'Hello BEAR'
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/Resource/Page/TextString.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TextString extends ResourceObject
{
public function onGet()
public function onGet(): static
{
$this->body = 'Hello BEAR';

Expand Down
6 changes: 4 additions & 2 deletions tests/IntegrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use BEAR\Streamer\Resource\Page\StreamArray;
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;
use Stringable;

use function assert;
use function method_exists;
Expand Down Expand Up @@ -77,8 +78,9 @@ public function testRender(string $uri, string $expected): void
$ro = $this->resource->newInstance($uri);
$ro->setRenderer($this->renderer);
assert(method_exists($ro, 'onGet'));
$view = (string) $ro->onGet();
$stream = $this->streamer->getStream($view);
$view = $ro->onGet();
assert($view instanceof Stringable);
$stream = $this->streamer->getStream((string) $view);
rewind($stream);
$view = stream_get_contents($stream);
$this->assertSame($expected, $view);
Expand Down
5 changes: 1 addition & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@

require dirname(__DIR__) . '/vendor/autoload.php';

// no annotation in PHP 8
if (PHP_MAJOR_VERSION >= 8) {
ServiceLocator::setReader(new AttributeReader());
}
ServiceLocator::setReader(new AttributeReader());
2 changes: 1 addition & 1 deletion tests/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function func_get_args;

function header(string $string, bool $replace = true, ?string $http_response_code = null): void
function header(string $string, bool $replace = true, string|null $http_response_code = null): void
{
/** @var array<string> $args */
$args = func_get_args();
Expand Down
16 changes: 8 additions & 8 deletions vendor-bin/tools/composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"require": {
"doctrine/coding-standard": "^11",
"phpmd/phpmd": "^2.9",
"phpmetrics/phpmetrics": "^2.7",
"phpstan/phpstan": "^0.12",
"psalm/plugin-phpunit": "^0.13",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^4.2"
"require-dev": {
"doctrine/coding-standard": "^12",
"phpmd/phpmd": "^2.15",
"phpmetrics/phpmetrics": "^2.8",
"phpstan/phpstan": "^2.0",
"squizlabs/php_codesniffer": "^3.11",
"vimeo/psalm": "^5.26"
koriym marked this conversation as resolved.
Show resolved Hide resolved
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}

Loading
Loading