Skip to content

Commit

Permalink
Add SonarCloud properties, add Sonar Github Workflow
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
mikaelcom committed Feb 9, 2023
1 parent 5b52d00 commit 9c7e6ca
Show file tree
Hide file tree
Showing 84 changed files with 847 additions and 792 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
run: echo $GITHUB_REF_NAME_SLUG

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get convenient Docker Meta
id: docker_meta
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/sonars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Sonars
on:
push:
branches:
- develop
- feature/*
- feat/*
- release/*
pull_request:
types: [ opened, synchronize, reopened ]
jobs:
sonarcloud:
name: Sonars
runs-on: ubuntu-latest
steps:
- name: Checkout code
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-clover coverage.xml --log-junit report.xml

- name: Monitor coverage
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
coverage_path: coverage.xml
threshold_alert: 95
threshold_warning: 90

- name: Fix phpunit files paths
run: sed -i 's@'$GITHUB_WORKSPACE/'@''@g' coverage.xml report.xml

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7 changes: 7 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sonar.projectKey=WsdlToPhp_PackageGenerator
sonar.organization=wsdltophp
sonar.php.coverage.reportPaths=coverage.xml
sonar.php.tests.reportPath=report.xml

sonar.sources=src/
sonar.tests=tests/
2 changes: 1 addition & 1 deletion src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class AbstractCommand extends Command

protected OutputInterface $output;

protected function configure()
protected function configure(): void
{
$this->addOption(
'force',
Expand Down
10 changes: 5 additions & 5 deletions src/ConfigurationReader/GeneratorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ protected function __construct(string $filename)
$this->parseOptions($filename);
}

public function __call($name, $arguments)
public function __call(string $name, array $arguments)
{
if ('set' === substr($name, 0, 3) && 1 === count($arguments)) {
if (0 === strpos($name, 'set') && 1 === count($arguments)) {
return $this->setOptionValue(self::methodNameToOptionName($name), array_shift($arguments));
}
if ('get' === substr($name, 0, 3) && empty($arguments)) {
if (empty($arguments) && 0 === strpos($name, 'get')) {
return $this->getOptionValue(self::methodNameToOptionName($name));
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public static function getDefaultConfigurationPath(): string

public static function methodNameToOptionName(string $name): string
{
return trim(strtolower(preg_replace(StructValue::MATCH_PATTERN, StructValue::REPLACEMENT_PATTERN, substr($name, 3))), '_');
return strtolower(trim(preg_replace(StructValue::MATCH_PATTERN, StructValue::REPLACEMENT_PATTERN, substr($name, 3)), '_'));
}

public function setAddComments(array $addComments = []): self
Expand Down Expand Up @@ -264,7 +264,7 @@ protected function parseOptions(string $filename): self
*
* @param mixed $value
*/
protected static function dotNotationToArray(string $string, $value, array &$array)
protected static function dotNotationToArray(string $string, $value, array &$array): void
{
$keys = explode('.', $string);
foreach ($keys as $key) {
Expand Down
12 changes: 5 additions & 7 deletions src/File/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ protected function addStructMethodAddTo(StructAttributeModel $attribute): self

protected function addStructMethodAddToBody(PhpMethod $method, StructAttributeModel $attribute): self
{
if ($this->getGenerator()->getOptionValidation()) {
$this->applyRules($method, $attribute, 'item', true);
}
$this->applyRules($method, $attribute, 'item', true);

if ($attribute->nameIsClean()) {
$assignment = sprintf('$this->%s[] = $item;', $attribute->getCleanName());
Expand Down Expand Up @@ -250,11 +248,9 @@ protected function addStructMethodSetBody(PhpMethod $method, StructAttributeMode
$parameters = $method->getParameters();
$parameter = array_shift($parameters);
$parameterName = is_string($parameter) ? $parameter : $parameter->getName();
if ($this->getGenerator()->getOptionValidation()) {
$this->applyRules($method, $attribute, $parameterName);
}

return $this
->applyRules($method, $attribute, $parameterName)
->addStructMethodSetBodyAssignment($method, $attribute, $parameterName)
->addStructMethodSetBodyReturn($method)
;
Expand Down Expand Up @@ -688,11 +684,13 @@ protected function getStructMethodsValidateLengthAnnotationBlock(PhpMethod $meth
]);
}

protected function applyRules(PhpMethod $method, StructAttributeModel $attribute, string $parameterName, bool $itemType = false): void
protected function applyRules(PhpMethod $method, StructAttributeModel $attribute, string $parameterName, bool $itemType = false): self
{
if ($this->getGenerator()->getOptionValidation()) {
$rules = new Rules($this, $method, $attribute, $this->methods);
$rules->applyRules($parameterName, $itemType);
}

return $this;
}
}
4 changes: 2 additions & 2 deletions src/Generator/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public static function saveSchemas(string $destinationFolder, string $schemasFol
$schemasPath = rtrim($destinationFolder, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.rtrim($schemasFolder, DIRECTORY_SEPARATOR);

// Here we must cover all possible variants
if ((false !== mb_strpos(mb_strtolower($schemasUrl), '.wsdl')) || (false !== mb_strpos(mb_strtolower($schemasUrl), '.xsd')) || (false !== mb_strpos(mb_strtolower($schemasUrl), '.xml'))) {
$filename = basename($schemasUrl);
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), '?'))) {
$filename = basename($schemasUrl) . (false === mb_strpos(basename($schemasUrl), '.') ? '.xsd' : '');
} else {
// if $url is like http://example.com/index.php?WSDL default filename will be schema.wsdl
$filename = 'schema.wsdl';
Expand Down
20 changes: 10 additions & 10 deletions tests/Command/GeneratePackageCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
final class GeneratePackageCommandTest extends AbstractTestCase
{
public function testExceptionOnDestination()
public function testExceptionOnDestination(): void
{
$this->expectException(InvalidArgumentException::class);

Expand All @@ -35,7 +35,7 @@ public function testExceptionOnDestination()
$command->run($input, $output);
}

public function testExceptionOnComposerName()
public function testExceptionOnComposerName(): void
{
$this->expectException(InvalidArgumentException::class);

Expand All @@ -52,7 +52,7 @@ public function testExceptionOnComposerName()
$command->run($input, $output);
}

public function testExceptionOnOrigin()
public function testExceptionOnOrigin(): void
{
$this->expectException(InvalidArgumentException::class);

Expand All @@ -69,7 +69,7 @@ public function testExceptionOnOrigin()
$command->run($input, $output);
}

public function testDebugMode()
public function testDebugMode(): void
{
AbstractYamlReader::resetInstances();
$command = new GeneratePackageCommand('WsdlToPhp');
Expand All @@ -88,7 +88,7 @@ public function testDebugMode()
$this->assertFalse(is_dir(self::getTestDirectory().'/debug/'));
}

public function testSetSrcDirname()
public function testSetSrcDirname(): void
{
AbstractYamlReader::resetInstances();
$command = new GeneratePackageCommand('WsdlToPhp');
Expand All @@ -109,7 +109,7 @@ public function testSetSrcDirname()
$this->assertSame('', $command->getGenerator()->getOptionSrcDirname());
}

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

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

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

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

public function testResolveGeneratorOptionsConfigPathUsingDefaultConfig()
public function testResolveGeneratorOptionsConfigPathUsingDefaultConfig(): void
{
$command = new GeneratePackageCommand('WsdlToPhp');
$input = new ArrayInput([
Expand Down
Loading

0 comments on commit 9c7e6ca

Please sign in to comment.