Skip to content

Commit

Permalink
Merge branch 'release/4.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Apr 20, 2023
2 parents f0393bc + 2eec5d9 commit d8ac0a4
Show file tree
Hide file tree
Showing 60 changed files with 1,678 additions and 9,374 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/sonars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Monitor coverage
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_path: coverage.xml
threshold_alert: 95
threshold_warning: 90
Expand All @@ -44,5 +44,5 @@ jobs:
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
60 changes: 60 additions & 0 deletions .github/workflows/static_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy code coverage content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["develop"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: xdebug

- name: Install dependencies with composer
run: composer update --no-ansi --no-interaction --no-progress

- name: Generate coverage report with phpunit
run: vendor/bin/phpunit --coverage-html=coverage

- name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: 'coverage'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## 4.1.8 - 2023-04-20
- issue #285, pr #288 - Type-Error when using regex pattern for decimal restriction
- issue #292, pr #293 - Wrong type for gYearMonth and gMonthDay
- pr #291 - Only cover src dir
- pr #281 - Add Rector PHP to ease code improvement
- issue #255, pr #283 - Class inheritance possibly misbehaving when having restriction tag
- issue #280, pr #282 - Optional parameters before required ones in constructor

## 4.1.7 - 2023-02-20
- Fix Github release workflow
-
## 4.1.6 - 2023-02-20
- issue #266, pr #270 - Usage of an undefined constant within a generate EnumType class #266
- pr #267 - Remove deprecated message
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Developers who helped on this project are listed in the [composer.json](composer
- [Clifford Vickrey](https://github.com/cliffordvickrey)
- [Arnaud POINTET](https://github.com/Oipnet)
- [dypa](https://github.com/dypa)
- [tbreuss](https://github.com/tbreuss)

## FAQ

Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
{
"name": "dypa",
"role": "Contributor"
},
{
"name": "tbreuss",
"email": "thomasbreuss@gmx.ch",
"role": "Contributor"
}
],
"support" : {
Expand All @@ -110,12 +115,14 @@
"test": "php-7.4 vendor/bin/phpunit",
"lint": "php-7.4 vendor/bin/php-cs-fixer fix --ansi --diff --verbose",
"build": "php-7.4 box build --verbose",
"phpstan": "php-7.4 vendor/bin/phpstan analyze src --level=2"
"phpstan": "php-7.4 vendor/bin/phpstan analyze src --level=2",
"rector": "php-7.4 vendor/bin/rector process"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^9"
"phpunit/phpunit": "^9",
"rector/rector": "^0.15.17"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 1 addition & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./</directory>
<directory>src</directory>
</include>
<exclude>
<directory>./src/resources</directory>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
Expand Down
35 changes: 35 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/src',
__DIR__.'/tests',
]);
$rectorConfig->skip([
__DIR__.'/tests/resources',
]);
// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);

// replace fully qualified class name by use statements
$rectorConfig->importShortClasses(false);
// keep native PHP class short name import
$rectorConfig->importNames();

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
$rectorConfig->rule(ReturnTypeFromStrictNativeCallRector::class);
$rectorConfig->rule(ReturnTypeFromStrictScalarReturnExprRector::class);
$rectorConfig->rule(ReturnTypeFromStrictTypedPropertyRector::class);
};
2 changes: 1 addition & 1 deletion src/Command/GeneratePackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ protected function formatOptionValue($optionValue)
protected function formatArrayForConsole(array $array): array
{
array_walk($array, function (&$value, $index) {
$value = sprintf('%s: %s', $index, json_encode($value));
$value = sprintf('%s: %s', $index, json_encode($value, JSON_THROW_ON_ERROR));
});

return $array;
Expand Down
3 changes: 1 addition & 2 deletions src/ConfigurationReader/AbstractReservedWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ abstract class AbstractReservedWord extends AbstractYamlReader
public const CASE_SENSITIVE_KEY = 'case_sensitive';
public const CASE_INSENSITIVE_KEY = 'case_insensitive';

protected array $keywords;
protected array $keywords = [];

protected function __construct(string $filename)
{
$this->keywords = [];
$this->parseReservedKeywords($filename);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ConfigurationReader/AbstractYamlReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function instance(?string $filename = null): self
throw new \InvalidArgumentException(sprintf('Unable to locate file "%s"', $loadFilename), __LINE__);
}

$key = sprintf('%s_%s', get_called_class(), $loadFilename);
$key = sprintf('%s_%s', static::class, $loadFilename);
if (!isset(self::$instances[$key])) {
self::$instances[$key] = new static($loadFilename);
}
Expand Down
3 changes: 1 addition & 2 deletions src/ConfigurationReader/GeneratorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ final class GeneratorOptions extends AbstractYamlReader implements \JsonSerializ
public const SCHEMAS_FOLDER = 'schemas_folder';
public const XSD_TYPES_PATH = 'xsd_types_path';

protected array $options;
protected array $options = [];

protected function __construct(string $filename)
{
$this->options = [];
$this->parseOptions($filename);
}

Expand Down
5 changes: 2 additions & 3 deletions src/ConfigurationReader/XsdTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ final class XsdTypes extends AbstractYamlReader
*/
public const ANONYMOUS_TYPE = '/anonymous\d+/';

protected array $types;
protected array $types = [];

protected function __construct(string $filename)
{
$this->types = [];
$this->parseXsdTypes($filename);
}

Expand All @@ -45,7 +44,7 @@ public static function isAnonymous(string $xsdType): bool

public function phpType(string $xsdType): string
{
return $this->isAnonymous($xsdType) ? $this->types[self::ANONYMOUS_KEY] : ($this->isXsd($xsdType) ? $this->types[$xsdType] : '');
return self::isAnonymous($xsdType) ? $this->types[self::ANONYMOUS_KEY] : ($this->isXsd($xsdType) ? $this->types[$xsdType] : '');
}

protected function parseXsdTypes(string $filename): self
Expand Down
7 changes: 6 additions & 1 deletion src/File/Validation/AbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ final public function applyRule(string $parameterName, $value, bool $itemType =

final public function validationRuleComment($value): string
{
return sprintf('// %s %s%s', self::VALIDATION_RULE_COMMENT_SENTENCE, $this->name(), is_array($value) ? sprintf('(%s)', implode(', ', array_unique($value))) : (empty($value) ? '' : sprintf('(%s)', $value)));
return sprintf(
'// %s %s%s',
self::VALIDATION_RULE_COMMENT_SENTENCE,
$this->name(),
is_array($value) ? sprintf('(%s)', implode(', ', array_unique($value))) : (empty($value) ? '' : sprintf('(%s)', $value))
);
}

abstract public function name(): string;
Expand Down
23 changes: 15 additions & 8 deletions src/File/Validation/PatternRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ public function name(): string
public function testConditions(string $parameterName, $value, bool $itemType = false): string
{
if ($itemType || !$this->getAttribute()->isArray()) {
$valueToMatch = self::valueToRegularExpression($value);
if (empty($valueToMatch)) {
return '';
}

$test = sprintf(
($itemType ? '' : '!is_null($%1$s) && ').'!preg_match(\'/%2$s/\', $%1$s)',
($itemType ? '' : '!is_null($%1$s) && ').'!preg_match(\'/%2$s/\', (string) $%1$s)',
$parameterName,
self::valueToRegularExpression($value)
);
Expand Down Expand Up @@ -60,14 +65,16 @@ public static function valueToRegularExpression($value): string
return implode(
'|',
array_map(
static function ($value) {
return addcslashes($value, '\'\\/');
},
static fn ($value) => addcslashes($value, '\'\\/'),
array_map(
static function ($value) {
return empty($value) ? '^$' : $value;
},
array_map('trim', is_array($value) ? $value : [$value])
static fn ($value) => empty($value) ? '^$' : $value,
array_map(
'trim',
array_filter(
is_array($value) ? $value : [$value],
static fn ($value) => !in_array($value, ['true', 'false', true, false], true)
)
)
)
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/File/Validation/UnionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ protected function addValidationMethod(string $parameterName, array $unionValues
unset($attribute);
}

// adapt content, remove duplicated rules
// duplicated rules is base don the fact that validation rules are composed by 4 lines so we check existing rule every 4-line block of text
// Adapt content, remove duplicated rules
// The duplicated rules are based on the fact that validation rules are composed by 4 lines so we check existing rule every 4-line block of text
$exceptions = 0;
$exceptionsTests = [];
$exceptionsArray = [];
Expand All @@ -69,7 +69,7 @@ protected function addValidationMethod(string $parameterName, array $unionValues
$childrenCount = count($methodChildren);
$existingValidationRules = [];
for ($i = 0; $i < $childrenCount; $i += 4) {
$validationRules = array_slice($methodChildren, ((int) $i / 4) * 4, 4);
$validationRules = array_slice($methodChildren, ((int) ($i / 4)) * 4, 4);
if (!in_array($validationRules, $existingValidationRules)) {
foreach ($validationRules as $validationRuleIndex => $validationRule) {
// avoid having a validation rule that has already been applied to the attribute within the method which is calling the validate method
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __call($name, $arguments)

return $this->options->{$getMethod}();
}
if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === count($arguments)) {
if (($prefix = 'setOption') === substr($name, 0, $length = strlen($prefix)) && 1 === (is_countable($arguments) ? count($arguments) : 0)) {
$setMethod = 'set'.substr($name, $length);
$this->options->{$setMethod}(array_shift($arguments));

Expand Down
6 changes: 3 additions & 3 deletions src/Generator/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function getPart(string $optionValue, string $string): string
switch ($optionValue) {
case GeneratorOptions::VALUE_END:
$parts = preg_split('/[A-Z]/', ucfirst($string));
$partsCount = count($parts);
$partsCount = is_countable($parts) ? count($parts) : 0;
if (!empty($parts[$partsCount - 1])) {
$elementType = mb_substr($string, mb_strrpos($string, implode('', array_slice($parts, -1))) - 1);
} else {
Expand All @@ -35,14 +35,14 @@ public static function getPart(string $optionValue, string $string): string
break;
}
}
$elementType = mb_substr($string, ((count($parts) - 2 - $i) + 1) * -1);
$elementType = mb_substr($string, (((is_countable($parts) ? count($parts) : 0) - 2 - $i) + 1) * -1);
}

break;

case GeneratorOptions::VALUE_START:
$parts = preg_split('/[A-Z]/', ucfirst($string));
$partsCount = count($parts);
$partsCount = is_countable($parts) ? count($parts) : 0;
if (empty($parts[0]) && !empty($parts[1])) {
$elementType = mb_substr($string, 0, mb_strlen($parts[1]) + 1);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public static function replacePhpReservedKeyword(string $keyword, ?string $conte

public function getReservedMethodsInstance(): AbstractReservedWord
{
throw new \InvalidArgumentException(sprintf('The method %s should be defined in the class %s', __FUNCTION__, get_called_class()));
throw new \InvalidArgumentException(sprintf('The method %s should be defined in the class %s', __FUNCTION__, static::class));
}

public function replaceReservedMethod(string $methodName, ?string $context = null): string
Expand Down Expand Up @@ -354,7 +354,7 @@ public function jsonSerialize(): array
'abstract' => $this->isAbstract,
'meta' => $this->meta,
'name' => $this->name,
'__CLASS__' => get_called_class(),
'__CLASS__' => static::class,
]);
}

Expand Down
Loading

0 comments on commit d8ac0a4

Please sign in to comment.