N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* Created by Bruno DA SILVA, working for Combodo
* Date: 31/12/2019
@@ -14,7 +15,6 @@ use PhpParser\PrettyPrinter\Standard;
class iTopConfigAstValidatorTest extends ItopTestCase
{
public function setUp(): void
{
parent::setUp();
@@ -23,7 +23,6 @@ class iTopConfigAstValidatorTest extends ItopTestCase
$this->RequireOnceItopFile('env-production/itop-config/src/Validator/iTopConfigAstValidator.php');
}
/**
* @dataProvider InvalidDataProvider
* @param $sConf
@@ -34,10 +33,9 @@ class iTopConfigAstValidatorTest extends ItopTestCase
{
$oiTopConfigValidator = new iTopConfigAstValidator();
$this->expectException(\Exception::class);
try{
try {
$oiTopConfigValidator->Validate($sConf);
}catch (\Exception $e)
{
} catch (\Exception $e) {
$this->assertStringStartsWith('Invalid configuration:', $e->getMessage());
throw $e;
}
@@ -45,29 +43,28 @@ class iTopConfigAstValidatorTest extends ItopTestCase
public function InvalidDataProvider()
{
return array(
'invalid PHP' => array(
'sConf' => '<?php fiction Method(){}'
),
'function call' => array(
'sConf' => '<?php FunctionCall();'
),
'function declaration' => array(
'sConf' => '<?php function foo() {};'
),
'class instantiation' => array(
'sConf' => '<?php new Class {};'
),
'Class declaration' => array(
'sConf' => '<?php class foo {};'
),
'echo' => array(
'sConf' => '<?php echo "toto"; ?>'
),
);
return [
'invalid PHP' => [
'sConf' => '<?php fiction Method(){}',
],
'function call' => [
'sConf' => '<?php FunctionCall();',
],
'function declaration' => [
'sConf' => '<?php function foo() {};',
],
'class instantiation' => [
'sConf' => '<?php new Class {};',
],
'Class declaration' => [
'sConf' => '<?php class foo {};',
],
'echo' => [
'sConf' => '<?php echo "toto"; ?>',
],
];
}
/**
* @dataProvider ValidDataProvider
* @doesNotPerformAssertions
@@ -85,13 +82,13 @@ class iTopConfigAstValidatorTest extends ItopTestCase
public function ValidDataProvider()
{
return array(
'simple code' => array(
'sConf' => '<?php $var = array("toto"); ?>'
),
'class constant' => array(
'sConf' => '<?php $var = array(foo::bar);'
),
);
return [
'simple code' => [
'sConf' => '<?php $var = array("toto"); ?>',
],
'class constant' => [
'sConf' => '<?php $var = array(foo::bar);',
],
];
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Created by Bruno DA SILVA, working for Combodo
* Date: 31/12/2019
@@ -15,7 +16,6 @@ use PhpParser\PrettyPrinter\Standard;
class iTopConfigSyntaxValidatorTest extends ItopTestCase
{
public function setUp(): void
{
parent::setUp();
@@ -24,7 +24,6 @@ class iTopConfigSyntaxValidatorTest extends ItopTestCase
$this->RequireOnceItopFile('env-production/itop-config/src/Validator/iTopConfigSyntaxValidator.php');
}
/**
* @throws \Exception
* @doesNotPerformAssertions
@@ -40,7 +39,7 @@ class iTopConfigSyntaxValidatorTest extends ItopTestCase
$oiTopConfigValidator = new iTopConfigSyntaxValidator();
$this->expectException(\Exception::class);
try{
try {
$oiTopConfigValidator->Validate("<?php \n zef;zefzef \n zdadz = azdazd \n zerfgzaezerfgzef>");
} catch (\Exception $e) {
if (version_compare(phpversion(), '8.0.0', '<')) {