Skip to content

Commit 9c7e6ca

Browse files
authored
Add SonarCloud properties, add Sonar Github Workflow
Minor improvements
1 parent 5b52d00 commit 9c7e6ca

File tree

84 files changed

+847
-792
lines changed

Some content is hidden

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

84 files changed

+847
-792
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ jobs:
4141
run: echo $GITHUB_REF_NAME_SLUG
4242

4343
- name: Checkout code
44-
uses: actions/checkout@v2
44+
uses: actions/checkout@v3
45+
with:
46+
fetch-depth: 0
4547

4648
- name: Get convenient Docker Meta
4749
id: docker_meta

.github/workflows/sonars.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Sonars
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
- feature/*
7+
- feat/*
8+
- release/*
9+
pull_request:
10+
types: [ opened, synchronize, reopened ]
11+
jobs:
12+
sonarcloud:
13+
name: Sonars
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup PHP with Xdebug
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: 7.4
25+
coverage: xdebug
26+
27+
- name: Install dependencies with composer
28+
run: composer update --no-ansi --no-interaction --no-progress
29+
30+
- name: Generate coverage report with phpunit
31+
run: vendor/bin/phpunit --coverage-clover coverage.xml --log-junit report.xml
32+
33+
- name: Monitor coverage
34+
uses: slavcodev/coverage-monitor-action@v1
35+
with:
36+
github_token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
37+
coverage_path: coverage.xml
38+
threshold_alert: 95
39+
threshold_warning: 90
40+
41+
- name: Fix phpunit files paths
42+
run: sed -i 's@'$GITHUB_WORKSPACE/'@''@g' coverage.xml report.xml
43+
44+
- name: SonarCloud Scan
45+
uses: SonarSource/sonarcloud-github-action@master
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
48+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar-project.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sonar.projectKey=WsdlToPhp_PackageGenerator
2+
sonar.organization=wsdltophp
3+
sonar.php.coverage.reportPaths=coverage.xml
4+
sonar.php.tests.reportPath=report.xml
5+
6+
sonar.sources=src/
7+
sonar.tests=tests/

src/Command/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class AbstractCommand extends Command
1717

1818
protected OutputInterface $output;
1919

20-
protected function configure()
20+
protected function configure(): void
2121
{
2222
$this->addOption(
2323
'force',

src/ConfigurationReader/GeneratorOptions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ protected function __construct(string $filename)
133133
$this->parseOptions($filename);
134134
}
135135

136-
public function __call($name, $arguments)
136+
public function __call(string $name, array $arguments)
137137
{
138-
if ('set' === substr($name, 0, 3) && 1 === count($arguments)) {
138+
if (0 === strpos($name, 'set') && 1 === count($arguments)) {
139139
return $this->setOptionValue(self::methodNameToOptionName($name), array_shift($arguments));
140140
}
141-
if ('get' === substr($name, 0, 3) && empty($arguments)) {
141+
if (empty($arguments) && 0 === strpos($name, 'get')) {
142142
return $this->getOptionValue(self::methodNameToOptionName($name));
143143
}
144144

@@ -182,7 +182,7 @@ public static function getDefaultConfigurationPath(): string
182182

183183
public static function methodNameToOptionName(string $name): string
184184
{
185-
return trim(strtolower(preg_replace(StructValue::MATCH_PATTERN, StructValue::REPLACEMENT_PATTERN, substr($name, 3))), '_');
185+
return strtolower(trim(preg_replace(StructValue::MATCH_PATTERN, StructValue::REPLACEMENT_PATTERN, substr($name, 3)), '_'));
186186
}
187187

188188
public function setAddComments(array $addComments = []): self
@@ -264,7 +264,7 @@ protected function parseOptions(string $filename): self
264264
*
265265
* @param mixed $value
266266
*/
267-
protected static function dotNotationToArray(string $string, $value, array &$array)
267+
protected static function dotNotationToArray(string $string, $value, array &$array): void
268268
{
269269
$keys = explode('.', $string);
270270
foreach ($keys as $key) {

src/File/Struct.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ protected function addStructMethodAddTo(StructAttributeModel $attribute): self
215215

216216
protected function addStructMethodAddToBody(PhpMethod $method, StructAttributeModel $attribute): self
217217
{
218-
if ($this->getGenerator()->getOptionValidation()) {
219-
$this->applyRules($method, $attribute, 'item', true);
220-
}
218+
$this->applyRules($method, $attribute, 'item', true);
221219

222220
if ($attribute->nameIsClean()) {
223221
$assignment = sprintf('$this->%s[] = $item;', $attribute->getCleanName());
@@ -250,11 +248,9 @@ protected function addStructMethodSetBody(PhpMethod $method, StructAttributeMode
250248
$parameters = $method->getParameters();
251249
$parameter = array_shift($parameters);
252250
$parameterName = is_string($parameter) ? $parameter : $parameter->getName();
253-
if ($this->getGenerator()->getOptionValidation()) {
254-
$this->applyRules($method, $attribute, $parameterName);
255-
}
256251

257252
return $this
253+
->applyRules($method, $attribute, $parameterName)
258254
->addStructMethodSetBodyAssignment($method, $attribute, $parameterName)
259255
->addStructMethodSetBodyReturn($method)
260256
;
@@ -688,11 +684,13 @@ protected function getStructMethodsValidateLengthAnnotationBlock(PhpMethod $meth
688684
]);
689685
}
690686

691-
protected function applyRules(PhpMethod $method, StructAttributeModel $attribute, string $parameterName, bool $itemType = false): void
687+
protected function applyRules(PhpMethod $method, StructAttributeModel $attribute, string $parameterName, bool $itemType = false): self
692688
{
693689
if ($this->getGenerator()->getOptionValidation()) {
694690
$rules = new Rules($this, $method, $attribute, $this->methods);
695691
$rules->applyRules($parameterName, $itemType);
696692
}
693+
694+
return $this;
697695
}
698696
}

src/Generator/Utils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public static function saveSchemas(string $destinationFolder, string $schemasFol
230230
$schemasPath = rtrim($destinationFolder, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.rtrim($schemasFolder, DIRECTORY_SEPARATOR);
231231

232232
// Here we must cover all possible variants
233-
if ((false !== mb_strpos(mb_strtolower($schemasUrl), '.wsdl')) || (false !== mb_strpos(mb_strtolower($schemasUrl), '.xsd')) || (false !== mb_strpos(mb_strtolower($schemasUrl), '.xml'))) {
234-
$filename = basename($schemasUrl);
233+
if ((false !== mb_strpos(mb_strtolower($schemasUrl), '.wsdl')) || (false !== mb_strpos(mb_strtolower($schemasUrl), '.xsd')) || (false !== mb_strpos(mb_strtolower($schemasUrl), '.xml')) || (false === mb_strpos(mb_strtolower($schemasUrl), '?'))) {
234+
$filename = basename($schemasUrl) . (false === mb_strpos(basename($schemasUrl), '.') ? '.xsd' : '');
235235
} else {
236236
// if $url is like http://example.com/index.php?WSDL default filename will be schema.wsdl
237237
$filename = 'schema.wsdl';

tests/Command/GeneratePackageCommandTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
final class GeneratePackageCommandTest extends AbstractTestCase
2121
{
22-
public function testExceptionOnDestination()
22+
public function testExceptionOnDestination(): void
2323
{
2424
$this->expectException(InvalidArgumentException::class);
2525

@@ -35,7 +35,7 @@ public function testExceptionOnDestination()
3535
$command->run($input, $output);
3636
}
3737

38-
public function testExceptionOnComposerName()
38+
public function testExceptionOnComposerName(): void
3939
{
4040
$this->expectException(InvalidArgumentException::class);
4141

@@ -52,7 +52,7 @@ public function testExceptionOnComposerName()
5252
$command->run($input, $output);
5353
}
5454

55-
public function testExceptionOnOrigin()
55+
public function testExceptionOnOrigin(): void
5656
{
5757
$this->expectException(InvalidArgumentException::class);
5858

@@ -69,7 +69,7 @@ public function testExceptionOnOrigin()
6969
$command->run($input, $output);
7070
}
7171

72-
public function testDebugMode()
72+
public function testDebugMode(): void
7373
{
7474
AbstractYamlReader::resetInstances();
7575
$command = new GeneratePackageCommand('WsdlToPhp');
@@ -88,7 +88,7 @@ public function testDebugMode()
8888
$this->assertFalse(is_dir(self::getTestDirectory().'/debug/'));
8989
}
9090

91-
public function testSetSrcDirname()
91+
public function testSetSrcDirname(): void
9292
{
9393
AbstractYamlReader::resetInstances();
9494
$command = new GeneratePackageCommand('WsdlToPhp');
@@ -109,7 +109,7 @@ public function testSetSrcDirname()
109109
$this->assertSame('', $command->getGenerator()->getOptionSrcDirname());
110110
}
111111

112-
public function testGetOptionValue()
112+
public function testGetOptionValue(): void
113113
{
114114
$command = new GeneratePackageCommand('WsdlToPhp');
115115
$input = new ArrayInput([
@@ -127,7 +127,7 @@ public function testGetOptionValue()
127127
$this->assertSame(__DIR__.'/../resources/generator_options.yml', $command->getGeneratorOptionsConfigOption());
128128
}
129129

130-
public function testResolveGeneratorOptionsConfigPathUsingOption()
130+
public function testResolveGeneratorOptionsConfigPathUsingOption(): void
131131
{
132132
$command = new GeneratePackageCommand('WsdlToPhp');
133133
$input = new ArrayInput([
@@ -145,7 +145,7 @@ public function testResolveGeneratorOptionsConfigPathUsingOption()
145145
$this->assertSame(__DIR__.'/../resources/generator_options.yml', $command->resolveGeneratorOptionsConfigPath());
146146
}
147147

148-
public function testResolveGeneratorOptionsConfigPathUsingExistingProperUserConfig()
148+
public function testResolveGeneratorOptionsConfigPathUsingExistingProperUserConfig(): void
149149
{
150150
$command = new GeneratePackageCommand('WsdlToPhp');
151151
$input = new ArrayInput([
@@ -163,7 +163,7 @@ public function testResolveGeneratorOptionsConfigPathUsingExistingProperUserConf
163163
$this->assertSame(realpath(self::getTestDirectory().'../existing_config/'.GeneratePackageCommand::PROPER_USER_CONFIGURATION), $command->resolveGeneratorOptionsConfigPath());
164164
}
165165

166-
public function testResolveGeneratorOptionsConfigPathUsingExistingDistributedConfig()
166+
public function testResolveGeneratorOptionsConfigPathUsingExistingDistributedConfig(): void
167167
{
168168
$command = new GeneratePackageCommand('WsdlToPhp');
169169
$input = new ArrayInput([
@@ -181,7 +181,7 @@ public function testResolveGeneratorOptionsConfigPathUsingExistingDistributedCon
181181
$this->assertSame(realpath(self::getTestDirectory().'../../../'.GeneratePackageCommand::DEFAULT_CONFIGURATION_FILE), $command->resolveGeneratorOptionsConfigPath());
182182
}
183183

184-
public function testResolveGeneratorOptionsConfigPathUsingDefaultConfig()
184+
public function testResolveGeneratorOptionsConfigPathUsingDefaultConfig(): void
185185
{
186186
$command = new GeneratePackageCommand('WsdlToPhp');
187187
$input = new ArrayInput([

0 commit comments

Comments
 (0)