Skip to content

Commit d8ac0a4

Browse files
committed
Merge branch 'release/4.1.8'
2 parents f0393bc + 2eec5d9 commit d8ac0a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1678
-9374
lines changed

.github/workflows/sonars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Monitor coverage
3434
uses: slavcodev/coverage-monitor-action@v1
3535
with:
36-
github_token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
3737
coverage_path: coverage.xml
3838
threshold_alert: 95
3939
threshold_warning: 90
@@ -44,5 +44,5 @@ jobs:
4444
- name: SonarCloud Scan
4545
uses: SonarSource/sonarcloud-github-action@master
4646
env:
47-
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/static_coverage.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy code coverage content to Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
branches: ["develop"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
# Single deploy job since we're just deploying
26+
deploy:
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v3
34+
with:
35+
fetch-depth: 0
36+
37+
- name: Setup PHP with Xdebug
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: 7.4
41+
coverage: xdebug
42+
43+
- name: Install dependencies with composer
44+
run: composer update --no-ansi --no-interaction --no-progress
45+
46+
- name: Generate coverage report with phpunit
47+
run: vendor/bin/phpunit --coverage-html=coverage
48+
49+
- name: Setup Pages
50+
uses: actions/configure-pages@v3
51+
52+
- name: Upload artifact
53+
uses: actions/upload-pages-artifact@v1
54+
with:
55+
# Upload entire repository
56+
path: 'coverage'
57+
58+
- name: Deploy to GitHub Pages
59+
id: deployment
60+
uses: actions/deploy-pages@v2

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# CHANGELOG
22

3+
## 4.1.8 - 2023-04-20
4+
- issue #285, pr #288 - Type-Error when using regex pattern for decimal restriction
5+
- issue #292, pr #293 - Wrong type for gYearMonth and gMonthDay
6+
- pr #291 - Only cover src dir
7+
- pr #281 - Add Rector PHP to ease code improvement
8+
- issue #255, pr #283 - Class inheritance possibly misbehaving when having restriction tag
9+
- issue #280, pr #282 - Optional parameters before required ones in constructor
10+
11+
## 4.1.7 - 2023-02-20
12+
- Fix Github release workflow
13+
-
314
## 4.1.6 - 2023-02-20
415
- issue #266, pr #270 - Usage of an undefined constant within a generate EnumType class #266
516
- pr #267 - Remove deprecated message

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ Developers who helped on this project are listed in the [composer.json](composer
162162
- [Clifford Vickrey](https://github.com/cliffordvickrey)
163163
- [Arnaud POINTET](https://github.com/Oipnet)
164164
- [dypa](https://github.com/dypa)
165+
- [tbreuss](https://github.com/tbreuss)
165166

166167
## FAQ
167168

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
{
8888
"name": "dypa",
8989
"role": "Contributor"
90+
},
91+
{
92+
"name": "tbreuss",
93+
"email": "[email protected]",
94+
"role": "Contributor"
9095
}
9196
],
9297
"support" : {
@@ -110,12 +115,14 @@
110115
"test": "php-7.4 vendor/bin/phpunit",
111116
"lint": "php-7.4 vendor/bin/php-cs-fixer fix --ansi --diff --verbose",
112117
"build": "php-7.4 box build --verbose",
113-
"phpstan": "php-7.4 vendor/bin/phpstan analyze src --level=2"
118+
"phpstan": "php-7.4 vendor/bin/phpstan analyze src --level=2",
119+
"rector": "php-7.4 vendor/bin/rector process"
114120
},
115121
"require-dev": {
116122
"friendsofphp/php-cs-fixer": "^3.0",
117123
"phpstan/phpstan": "^1.3",
118-
"phpunit/phpunit": "^9"
124+
"phpunit/phpunit": "^9",
125+
"rector/rector": "^0.15.17"
119126
},
120127
"autoload": {
121128
"psr-4": {

phpunit.xml.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
<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">
33
<coverage>
44
<include>
5-
<directory>./</directory>
5+
<directory>src</directory>
66
</include>
7-
<exclude>
8-
<directory>./src/resources</directory>
9-
<directory>./tests</directory>
10-
<directory>./vendor</directory>
11-
</exclude>
127
</coverage>
138
<php>
149
<ini name="error_reporting" value="-1"/>

rector.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
7+
use Rector\Config\RectorConfig;
8+
use Rector\Set\ValueObject\LevelSetList;
9+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
10+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
11+
12+
return static function (RectorConfig $rectorConfig): void {
13+
$rectorConfig->paths([
14+
__DIR__.'/src',
15+
__DIR__.'/tests',
16+
]);
17+
$rectorConfig->skip([
18+
__DIR__.'/tests/resources',
19+
]);
20+
// define sets of rules
21+
$rectorConfig->sets([
22+
LevelSetList::UP_TO_PHP_74,
23+
]);
24+
25+
// replace fully qualified class name by use statements
26+
$rectorConfig->importShortClasses(false);
27+
// keep native PHP class short name import
28+
$rectorConfig->importNames();
29+
30+
// register a single rule
31+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
32+
$rectorConfig->rule(ReturnTypeFromStrictNativeCallRector::class);
33+
$rectorConfig->rule(ReturnTypeFromStrictScalarReturnExprRector::class);
34+
$rectorConfig->rule(ReturnTypeFromStrictTypedPropertyRector::class);
35+
};

src/Command/GeneratePackageCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ protected function formatOptionValue($optionValue)
363363
protected function formatArrayForConsole(array $array): array
364364
{
365365
array_walk($array, function (&$value, $index) {
366-
$value = sprintf('%s: %s', $index, json_encode($value));
366+
$value = sprintf('%s: %s', $index, json_encode($value, JSON_THROW_ON_ERROR));
367367
});
368368

369369
return $array;

src/ConfigurationReader/AbstractReservedWord.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ abstract class AbstractReservedWord extends AbstractYamlReader
1010
public const CASE_SENSITIVE_KEY = 'case_sensitive';
1111
public const CASE_INSENSITIVE_KEY = 'case_insensitive';
1212

13-
protected array $keywords;
13+
protected array $keywords = [];
1414

1515
protected function __construct(string $filename)
1616
{
17-
$this->keywords = [];
1817
$this->parseReservedKeywords($filename);
1918
}
2019

src/ConfigurationReader/AbstractYamlReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function instance(?string $filename = null): self
2323
throw new \InvalidArgumentException(sprintf('Unable to locate file "%s"', $loadFilename), __LINE__);
2424
}
2525

26-
$key = sprintf('%s_%s', get_called_class(), $loadFilename);
26+
$key = sprintf('%s_%s', static::class, $loadFilename);
2727
if (!isset(self::$instances[$key])) {
2828
self::$instances[$key] = new static($loadFilename);
2929
}

src/ConfigurationReader/GeneratorOptions.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ final class GeneratorOptions extends AbstractYamlReader implements \JsonSerializ
123123
public const SCHEMAS_FOLDER = 'schemas_folder';
124124
public const XSD_TYPES_PATH = 'xsd_types_path';
125125

126-
protected array $options;
126+
protected array $options = [];
127127

128128
protected function __construct(string $filename)
129129
{
130-
$this->options = [];
131130
$this->parseOptions($filename);
132131
}
133132

src/ConfigurationReader/XsdTypes.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ final class XsdTypes extends AbstractYamlReader
1515
*/
1616
public const ANONYMOUS_TYPE = '/anonymous\d+/';
1717

18-
protected array $types;
18+
protected array $types = [];
1919

2020
protected function __construct(string $filename)
2121
{
22-
$this->types = [];
2322
$this->parseXsdTypes($filename);
2423
}
2524

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

4645
public function phpType(string $xsdType): string
4746
{
48-
return $this->isAnonymous($xsdType) ? $this->types[self::ANONYMOUS_KEY] : ($this->isXsd($xsdType) ? $this->types[$xsdType] : '');
47+
return self::isAnonymous($xsdType) ? $this->types[self::ANONYMOUS_KEY] : ($this->isXsd($xsdType) ? $this->types[$xsdType] : '');
4948
}
5049

5150
protected function parseXsdTypes(string $filename): self

src/File/Validation/AbstractRule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ final public function applyRule(string $parameterName, $value, bool $itemType =
4242

4343
final public function validationRuleComment($value): string
4444
{
45-
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)));
45+
return sprintf(
46+
'// %s %s%s',
47+
self::VALIDATION_RULE_COMMENT_SENTENCE,
48+
$this->name(),
49+
is_array($value) ? sprintf('(%s)', implode(', ', array_unique($value))) : (empty($value) ? '' : sprintf('(%s)', $value))
50+
);
4651
}
4752

4853
abstract public function name(): string;

src/File/Validation/PatternRule.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ public function name(): string
2222
public function testConditions(string $parameterName, $value, bool $itemType = false): string
2323
{
2424
if ($itemType || !$this->getAttribute()->isArray()) {
25+
$valueToMatch = self::valueToRegularExpression($value);
26+
if (empty($valueToMatch)) {
27+
return '';
28+
}
29+
2530
$test = sprintf(
26-
($itemType ? '' : '!is_null($%1$s) && ').'!preg_match(\'/%2$s/\', $%1$s)',
31+
($itemType ? '' : '!is_null($%1$s) && ').'!preg_match(\'/%2$s/\', (string) $%1$s)',
2732
$parameterName,
2833
self::valueToRegularExpression($value)
2934
);
@@ -60,14 +65,16 @@ public static function valueToRegularExpression($value): string
6065
return implode(
6166
'|',
6267
array_map(
63-
static function ($value) {
64-
return addcslashes($value, '\'\\/');
65-
},
68+
static fn ($value) => addcslashes($value, '\'\\/'),
6669
array_map(
67-
static function ($value) {
68-
return empty($value) ? '^$' : $value;
69-
},
70-
array_map('trim', is_array($value) ? $value : [$value])
70+
static fn ($value) => empty($value) ? '^$' : $value,
71+
array_map(
72+
'trim',
73+
array_filter(
74+
is_array($value) ? $value : [$value],
75+
static fn ($value) => !in_array($value, ['true', 'false', true, false], true)
76+
)
77+
)
7178
)
7279
)
7380
);

src/File/Validation/UnionRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ protected function addValidationMethod(string $parameterName, array $unionValues
5959
unset($attribute);
6060
}
6161

62-
// adapt content, remove duplicated rules
63-
// 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
62+
// Adapt content, remove duplicated rules
63+
// 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
6464
$exceptions = 0;
6565
$exceptionsTests = [];
6666
$exceptionsArray = [];
@@ -69,7 +69,7 @@ protected function addValidationMethod(string $parameterName, array $unionValues
6969
$childrenCount = count($methodChildren);
7070
$existingValidationRules = [];
7171
for ($i = 0; $i < $childrenCount; $i += 4) {
72-
$validationRules = array_slice($methodChildren, ((int) $i / 4) * 4, 4);
72+
$validationRules = array_slice($methodChildren, ((int) ($i / 4)) * 4, 4);
7373
if (!in_array($validationRules, $existingValidationRules)) {
7474
foreach ($validationRules as $validationRuleIndex => $validationRule) {
7575
// avoid having a validation rule that has already been applied to the attribute within the method which is calling the validate method

src/Generator/Generator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __call($name, $arguments)
107107

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

src/Generator/Utils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function getPart(string $optionValue, string $string): string
2525
switch ($optionValue) {
2626
case GeneratorOptions::VALUE_END:
2727
$parts = preg_split('/[A-Z]/', ucfirst($string));
28-
$partsCount = count($parts);
28+
$partsCount = is_countable($parts) ? count($parts) : 0;
2929
if (!empty($parts[$partsCount - 1])) {
3030
$elementType = mb_substr($string, mb_strrpos($string, implode('', array_slice($parts, -1))) - 1);
3131
} else {
@@ -35,14 +35,14 @@ public static function getPart(string $optionValue, string $string): string
3535
break;
3636
}
3737
}
38-
$elementType = mb_substr($string, ((count($parts) - 2 - $i) + 1) * -1);
38+
$elementType = mb_substr($string, (((is_countable($parts) ? count($parts) : 0) - 2 - $i) + 1) * -1);
3939
}
4040

4141
break;
4242

4343
case GeneratorOptions::VALUE_START:
4444
$parts = preg_split('/[A-Z]/', ucfirst($string));
45-
$partsCount = count($parts);
45+
$partsCount = is_countable($parts) ? count($parts) : 0;
4646
if (empty($parts[0]) && !empty($parts[1])) {
4747
$elementType = mb_substr($string, 0, mb_strlen($parts[1]) + 1);
4848
} else {

src/Model/AbstractModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public static function replacePhpReservedKeyword(string $keyword, ?string $conte
308308

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

314314
public function replaceReservedMethod(string $methodName, ?string $context = null): string
@@ -354,7 +354,7 @@ public function jsonSerialize(): array
354354
'abstract' => $this->isAbstract,
355355
'meta' => $this->meta,
356356
'name' => $this->name,
357-
'__CLASS__' => get_called_class(),
357+
'__CLASS__' => static::class,
358358
]);
359359
}
360360

0 commit comments

Comments
 (0)