Skip to content

Commit

Permalink
drop php 7.4, improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Sep 27, 2023
1 parent f5eb5a8 commit 28008c1
Show file tree
Hide file tree
Showing 41 changed files with 107 additions and 158 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
coverage: none

- name: Composer install
Expand Down Expand Up @@ -66,9 +66,6 @@ jobs:
- name: Run check style
run: make lint-ecs

- name: Run copy/paste detection
run: make qa-phpcpd

- name: Run mess detection
run: make qa-phpmd

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
coverage: none

- name: Composer install
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ fix:
make --no-print-directory fix-ecs


.PHONY: qa-phpcpd
qa-phpcpd:
vendor/bin/phpcpd src tests

.PHONY: qa-phpmd
qa-phpmd:
vendor/bin/phpmd src,tests ansi unusedcode,naming,design,controversial,codesize
Expand All @@ -46,7 +42,6 @@ qa-phpstan:

.PHONY: qa
qa:
make --no-print-directory qa-phpcpd && \
make --no-print-directory qa-phpmd && \
make --no-print-directory qa-phpmnd && \
make --no-print-directory qa-compatibility && \
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![PHP version](https://img.shields.io/badge/PHP-%3E%3D7.4-8892BF.svg?style=flat-square)](http://php.net)
[![PHP version](https://img.shields.io/badge/PHP-%3E%3D8.0-8892BF.svg?style=flat-square)](http://php.net)
[![Latest Version](https://img.shields.io/packagist/v/juliangut/mapping.svg?style=flat-square)](https://packagist.org/packages/juliangut/mapping)
[![License](https://img.shields.io/github/license/juliangut/mapping.svg?style=flat-square)](https://github.com/juliangut/mapping/blob/master/LICENSE)

Expand Down Expand Up @@ -108,7 +108,7 @@ $driver->getMetadata();

#### Annotation mapping

_Annotations are deprecated and will be removed when support for PHP 7.4 is dropped. Use Attribute mapping instead_
_Annotations are deprecated and discouraged. Use Attribute mapping instead_

```
composer require doctrine/annotations
Expand Down Expand Up @@ -193,7 +193,7 @@ $metadata = $metadataResolver->getMetadata($mappingSources);

Define where your mapping data is and how it will be parsed

* `type` one of \Jgut\Mapping\Driver\DriverFactoryInterface constants: `DRIVER_ATTRIBUTE`, `DRIVER_PHP`, `DRIVER_JSON`, `DRIVER_XML`, `DRIVER_YAML` or `DRIVER_ANNOTATION` **if no driver, defaults to DRIVER_ATTRIBUTE in PHP >=8.0 or DRIVER_ANNOTATION PHP < 8.0**
* `type` one of \Jgut\Mapping\Driver\DriverFactoryInterface constants: `DRIVER_ATTRIBUTE`, `DRIVER_PHP`, `DRIVER_JSON`, `DRIVER_XML`, `DRIVER_YAML` or `DRIVER_ANNOTATION` **if no driver, defaults to DRIVER_ATTRIBUTE**
* `path` a string path or array of paths to where mapping files are located (files or directories) **REQUIRED if no driver**
* `driver` an already created \Jgut\Mapping\Driver\DriverInterface object **REQUIRED if no type AND path**

Expand Down
26 changes: 10 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,24 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"psr/simple-cache": "^1.0"
},
"require-dev": {
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"doctrine/annotations": "^1.13.3",
"grifart/phpstan-oneline": "~0.4",
"infection/infection": "~0.24",
"juliangut/easy-coding-standard-config": "^1.0",
"overtrue/phplint": "^3.0|^4.0|^5.0|^6.0",
"doctrine/annotations": "^2.0",
"infection/infection": "~0.25|~0.27",
"juliangut/easy-coding-standard-config": "^1.12",
"juliangut/phpstan-config": "^1.1",
"overtrue/phplint": "^4.0|^5.0|^6.0",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.10",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"povils/phpmnd": "^2.5",
"phpmd/phpmd": "^2.13",
"phpunit/phpunit": "^9.6|^10.3",
"povils/phpmnd": "^3.2",
"roave/security-advisories": "dev-master",
"sebastian/phpcpd": "^6.0",
"symfony/yaml": "^5.0.10",
"thecodingmachine/phpstan-strict-rules": "^1.0"
"symfony/yaml": "^6.0"
},
"suggest": {
"doctrine/annotations": "(^1.4) In order to load mappings from class annotations",
Expand Down
12 changes: 3 additions & 9 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

declare(strict_types=1);

use Jgut\ECS\Config\ConfigSet74;
use Jgut\ECS\Config\ConfigSet80;
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\NoSilencedErrorsSniff;
use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

$header = <<<'HEADER'
Expand All @@ -32,16 +31,11 @@
__DIR__ . '/tests',
]);

(new ConfigSet74())
(new ConfigSet80())
->setHeader($header)
->enablePhpUnitRules()
->setAdditionalRules([
NativeConstantInvocationFixer::class => [
'exclude' => ['null', 'false', 'true', 'T_NAME_QUALIFIED'], // Temporal while supporting PHP 7.4
],
])
->setAdditionalSkips([
NoSilencedErrorsSniff::class . '.Discouraged' => [
NoSilencedErrorsSniff::class . '.Forbidden' => [
__DIR__ . '/src/Driver/AbstractAnnotationDriver.php', // Temporal while deprecating annotations
],
])
Expand Down
6 changes: 3 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- %rootDir%/../../juliangut/phpstan-config/phpstan-phpunit.neon

parameters:
level: max
checkMissingCallableSignature: true
tipsOfTheDay: false
errorFormat: compact
parallel:
maximumNumberOfProcesses: 7
paths:
- src
ignoreErrors:
- message: '/^Parameter #1 \$callback of function array_map expects \(callable\(.+\): mixed\)\|null, Closure\(.+\): .+ given\.$/'
path: src/Metadata/MetadataResolver.php
- message: '/^Error suppression via "@" should not be used\.$/'
path: src/Driver/AbstractAnnotationDriver.php
- message: '/^Instanceof between SimpleXMLElement and SimpleXMLElement will always evaluate to true\.$/'
path: src/Driver/Traits/XmlMappingTrait.php
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
Expand Down
16 changes: 6 additions & 10 deletions src/Driver/AbstractAnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@

abstract class AbstractAnnotationDriver extends AbstractClassDriver
{
protected Reader $annotationReader;

/**
* @param array<string> $paths
* @param list<string> $paths
*/
public function __construct(array $paths, Reader $annotationReader)
{
if (\PHP_VERSION_ID >= 80_000) {
@trigger_error('Annotations are deprecated. Use PHP Attributes instead.', \E_USER_DEPRECATED);
}
public function __construct(
array $paths,
protected Reader $annotationReader,
) {
@trigger_error('Annotations are deprecated. Use PHP Attributes instead.', \E_USER_DEPRECATED);

parent::__construct($paths);

$this->annotationReader = $annotationReader;
}
}
7 changes: 1 addition & 6 deletions src/Driver/AbstractClassDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ private function findNextToken(array $tokens, array $types, int $start = 0, ?int
*/
private function getValidTokenTypes(): array
{
$validTokenTypes = [\T_WHITESPACE, \T_NS_SEPARATOR, \T_STRING];
if (\PHP_VERSION_ID >= 80_000) {
$validTokenTypes[] = T_NAME_QUALIFIED;
}

return $validTokenTypes;
return [\T_WHITESPACE, \T_NS_SEPARATOR, \T_STRING, \T_NAME_QUALIFIED];
}
}
4 changes: 2 additions & 2 deletions src/Driver/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractDriver implements DriverInterface
protected FileLocator $locator;

/**
* @param array<string> $paths
* @param list<string> $paths
*/
public function __construct(array $paths)
{
Expand All @@ -30,7 +30,7 @@ public function __construct(array $paths)
/**
* Get supported mapping file extensions.
*
* @return array<string>
* @return list<string>
*/
abstract protected function getExtensions(): array;
}
2 changes: 1 addition & 1 deletion src/Driver/AbstractDriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getDriver(array $mappingSource): DriverInterface
throw new DriverException(sprintf(
'Metadata mapping driver should be of the type "%s", "%s" given.',
DriverInterface::class,
\is_object($driver) ? \get_class($driver) : \gettype($driver),
\is_object($driver) ? $driver::class : \gettype($driver),
));
}

Expand Down
29 changes: 10 additions & 19 deletions src/Driver/Locator/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,16 @@

class FileLocator
{
/**
* @var array<string>
*/
protected array $paths = [];

/**
* @var array<string>
*/
protected array $extensions;

/**
* @param array<string> $paths
* @param array<string> $extensions
*/
public function __construct(array $paths, array $extensions)
{
$this->paths = $paths;
$this->extensions = $extensions;
}
public function __construct(
/**
* @var list<string>
*/
protected array $paths,
/**
* @var list<string>
*/
protected array $extensions,
) {}

/**
* @return array<string>
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/AnnotationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use RuntimeException;

class AnnotationException extends RuntimeException
{
}
class AnnotationException extends RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exception/AttributeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use RuntimeException;

class AttributeException extends RuntimeException
{
}
class AttributeException extends RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exception/DriverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use RuntimeException;

class DriverException extends RuntimeException
{
}
class DriverException extends RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exception/MetadataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use RuntimeException;

class MetadataException extends RuntimeException
{
}
class MetadataException extends RuntimeException {}
4 changes: 1 addition & 3 deletions src/Metadata/MetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Jgut\Mapping\Metadata;

interface MetadataInterface
{
}
interface MetadataInterface {}
24 changes: 7 additions & 17 deletions src/Metadata/MetadataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@
class MetadataResolver
{
/**
* Driver factory.
* @param CacheInterface<mixed>|null $cache
*/
protected DriverFactoryInterface $driverFactory;

/**
* Metadata cache.
*/
protected ?CacheInterface $cache;

public function __construct(DriverFactoryInterface $driverFactory, ?CacheInterface $cache = null)
{
$this->driverFactory = $driverFactory;
$this->cache = $cache;
}
public function __construct(
protected DriverFactoryInterface $driverFactory,
protected ?CacheInterface $cache = null,
) {}

/**
* @param array<Source> $mappingSources
Expand Down Expand Up @@ -94,7 +86,7 @@ static function (array $mappingSource): string {
),
);

return sha1($key);
return hash('sha256', $key);
}

/**
Expand All @@ -106,9 +98,7 @@ static function (array $mappingSource): string {
*/
protected function normalizeMappingSources(array $mappingSources): array
{
$defaultDriver = \PHP_VERSION_ID >= 80_000
? DriverFactoryInterface::DRIVER_ATTRIBUTE
: DriverFactoryInterface::DRIVER_ANNOTATION;
$defaultDriver = DriverFactoryInterface::DRIVER_ATTRIBUTE;

return array_map(
static function ($mappingSource) use ($defaultDriver): array {
Expand Down
4 changes: 0 additions & 4 deletions tests/Mapping/Driver/AbstractAttributeDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public function testMappings(): void

public function testAttributes(): void
{
if (\PHP_VERSION_ID < 80_000) {
static::markTestSkipped('No attributes in PHP < 8.0.');
}

$driver = new AbstractAttributeDriverStub([__DIR__ . '/../Files/Classes/Valid/Attribute']);

$attributes = $driver->getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
/**
* @Stub("myClassA", path="path")
*/
class ClassInvalidMethod
{
}
class ClassInvalidMethod {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
/**
* @Stub()
*/
class ClassInvalidProperty
{
}
class ClassInvalidProperty {}
Loading

0 comments on commit 28008c1

Please sign in to comment.