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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.4-cli
FROM php:8.4-cli

# Install system dependencies
RUN apt-get update && apt-get install -y \
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
}
],
"require": {
"php": "^7.1"
"php": "^8.4"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.47",
"nikic/php-parser": "^4.1",
"phpstan/phpstan": "^0.11",
"phpunit/phpunit": "^8.0"
"nikic/php-parser": "^5.6",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^12.3"
},
"replace": {
"gabrielelana/precious": "self.version"
},
"suggest": {
"nikic/php-parser": "^4.1",
"phpstan/phpstan": "^0.11"
"nikic/php-parser": "^5.6",
"phpstan/phpstan": "^2.1"
},
"minimum-stability": "stable",
"autoload": {
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ includes:

parameters:
level: 7
excludes_analyse:
paths:
- src
- tests
excludePaths:
- %currentWorkingDirectory%/vendor/
- %currentWorkingDirectory%/tests/*/data/*
- %currentWorkingDirectory%/tests/PreciousTest.php
36 changes: 17 additions & 19 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php">
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="unit">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="true"
bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="unit">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
9 changes: 3 additions & 6 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ interface Field
{
/**
* Returns the name of the field
*
* @returns string
*/
public function name();
public function name(): string;

/**
* Returns the value of the field picked from an array of values
*
* @param array<mixed> $parameters
* @throws MissingRequiredFieldException
*
* @returns mixed
*/
public function pickIn(array $parameters);
public function pickIn(array $parameters): mixed;
}
31 changes: 13 additions & 18 deletions src/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,50 @@

use Iterator;

/**
* @implements Iterator<int, Field>
*/
class Fields implements Iterator
{
/**
* @var int
*/
private $position;

/**
* @var array<Field>
*/
private $fields;
private int $position;

/**
* @var array<Field> $fields
* @param array<Field> $fields
* @throws NameClashFieldException
* @returns self
*/
public function __construct(array $fields) {
public function __construct(private readonly array $fields) {
$this->position = 0;
$this->fields = $fields;
self::ensureUniqueNames(
array_map(function($field) { return $field->name(); }, $fields)
);
}

public function rewind() {
public function rewind(): void {
$this->position = 0;
}

public function current() {
public function current(): Field {
return $this->fields[$this->position];
}

public function key() {
public function key(): int {
return $this->position;
}

public function next() {
public function next(): void {
++$this->position;
}

public function valid() {
public function valid(): bool {
return isset($this->fields[$this->position]);
}

/**
* @param array<string> $declaredNames;
* @throws NameClashFieldException
*/
private static function ensureUniqueNames(array $declaredNames) : void
private static function ensureUniqueNames(array $declaredNames): void
{
$uniqueNames = array_unique($declaredNames);
if (count($declaredNames) !== count($uniqueNames)) {
Expand Down
20 changes: 4 additions & 16 deletions src/OptionalField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@

class OptionalField extends RequiredField
{
/**
* @var mixed $defaultValue
*/
private $defaultValue;
private mixed $defaultValue;

/**
* @var string $name
* @var Type $type
* @var mixed $defaultValue
*
* @returns self
*/
public function __construct(string $name, Type $type, $defaultValue)
public function __construct(string $name, Type $type, mixed $defaultValue)
{
parent::__construct($name, $type);
$this->defaultValue = $defaultValue;
Expand All @@ -27,12 +17,12 @@ public function __construct(string $name, Type $type, $defaultValue)
/**
* Returns the value of the field picked from an array of values
*
* @param array<mixed> $parameters
* @throws WrongTypeFieldException
* @throws MissingRequiredFieldException
*
* @returns mixed
*/
public function pickIn(array $parameters)
public function pickIn(array $parameters): mixed
{
try {
return parent::pickIn($parameters);
Expand All @@ -42,13 +32,11 @@ public function pickIn(array $parameters)
return null;
}
return $this->cast($this->defaultValue);

} catch (WrongTypeFieldException $e) {
if (null === $this->defaultValue) {
return null;
}
throw $e;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,17 @@
namespace Precious\PHPStan\Reflection;

use PHPStan\Broker\Broker;
use PHPStan\Reflection\BrokerAwareExtension;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use Precious\Precious;

class PreciousPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension, BrokerAwareExtension
class PreciousPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{
/** @var Broker */
private $broker;

/** @var array<array<Property>> */
private $properties;
private array $properties;

/**
* @param Broker $broker Class reflection broker
* @return void
*/
public function setBroker(Broker $broker) : void
{
$this->broker = $broker;
$this->properties = [];
}

/**
* @param ClassReflection $classReflection
Expand Down
Loading