Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 8b25291

Browse files
author
Dominik František Bučík
authored
Merge pull request #270 from CESNET/ecs
style: update ECS, fix ECS config
2 parents d51e49f + 6d5cc13 commit 8b25291

68 files changed

Lines changed: 378 additions & 272 deletions

Some content is hidden

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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"web-token/jwt-core": "^2.2"
6262
},
6363
"require-dev": {
64-
"symplify/easy-coding-standard": "^10.0"
64+
"symplify/easy-coding-standard": "^10.2"
6565
},
6666
"suggest": {
6767
"cesnet/simplesamlphp-module-privacyidea": "included privacyIDEA template is for this module"

composer.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs.php

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
declare(strict_types=1);
44

5-
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
65
use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer;
76
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
8-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9-
use Symplify\EasyCodingStandard\ValueObject\Option;
7+
use Symplify\EasyCodingStandard\Config\ECSConfig;
108
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
119

12-
return static function (ContainerConfigurator $containerConfigurator): void {
13-
$parameters = $containerConfigurator->parameters();
14-
$parameters->set(Option::PATHS, [
10+
return static function (ECSConfig $ecsConfig): void {
11+
$ecsConfig->paths([
1512
__DIR__ . '/ecs.php',
1613
__DIR__ . '/config-templates',
1714
__DIR__ . '/hooks',
@@ -20,28 +17,21 @@
2017
__DIR__ . '/themes',
2118
__DIR__ . '/www',
2219
]);
23-
$parameters->set(Option::PARALLEL, true);
24-
$parameters->set(Option::SKIP, [NotOperatorWithSuccessorSpaceFixer::class, FunctionTypehintSpaceFixer::class]);
2520

26-
$containerConfigurator->import(SetList::PHP_CS_FIXER);
27-
$containerConfigurator->import(SetList::CLEAN_CODE);
28-
$containerConfigurator->import(SetList::SYMPLIFY);
29-
$containerConfigurator->import(SetList::ARRAY);
30-
$containerConfigurator->import(SetList::COMMON);
31-
$containerConfigurator->import(SetList::COMMENTS);
32-
$containerConfigurator->import(SetList::CONTROL_STRUCTURES);
33-
$containerConfigurator->import(SetList::DOCBLOCK);
34-
$containerConfigurator->import(SetList::NAMESPACES);
35-
$containerConfigurator->import(SetList::PHPUNIT);
36-
$containerConfigurator->import(SetList::SPACES);
37-
$containerConfigurator->import(SetList::STRICT);
38-
$containerConfigurator->import(SetList::SYMFONY);
39-
$containerConfigurator->import(SetList::PSR_12);
21+
$ecsConfig->sets([
22+
SetList::CLEAN_CODE,
23+
SetList::SYMPLIFY,
24+
SetList::ARRAY,
25+
SetList::COMMON,
26+
SetList::COMMENTS,
27+
SetList::CONTROL_STRUCTURES,
28+
SetList::DOCBLOCK,
29+
SetList::NAMESPACES,
30+
SetList::PHPUNIT,
31+
SetList::SPACES,
32+
SetList::STRICT,
33+
SetList::PSR_12,
34+
]);
4035

41-
$services = $containerConfigurator->services();
42-
$services->set(ArraySyntaxFixer::class)
43-
->call('configure', [[
44-
'syntax' => 'short',
45-
]])
46-
;
36+
$ecsConfig->skip([NotOperatorWithSuccessorSpaceFixer::class, FunctionTypehintSpaceFixer::class]);
4737
};

hooks/hook_cron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
function perun_hook_cron(&$croninfo)
1414
{
15-
if ('hourly' !== $croninfo['tag']) {
15+
if ($croninfo['tag'] !== 'hourly') {
1616
Logger::debug('cron [perun]: Skipping cron in cron tag [' . $croninfo['tag'] . '] ');
1717

1818
return;

lib/Adapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public function getConnector()
3737
*/
3838
public static function getInstance($interface)
3939
{
40-
if (self::RPC === $interface) {
40+
if ($interface === self::RPC) {
4141
return new AdapterRpc();
4242
}
43-
if (self::LDAP === $interface) {
43+
if ($interface === self::LDAP) {
4444
return new AdapterLdap();
4545
}
4646
throw new Exception('Unknown perun interface. Hint: try ' . self::RPC . ' or ' . self::LDAP);

lib/AdapterLdap.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AdapterLdap extends Adapter
6767

6868
public function __construct($configFileName = null)
6969
{
70-
if (null === $configFileName) {
70+
if ($configFileName === null) {
7171
$configFileName = self::DEFAULT_CONFIG_FILE_NAME;
7272
}
7373

@@ -248,7 +248,7 @@ public function getGroupByName($vo, $name)
248248
'(&(objectClass=perunGroup)(perunUniqueGroupName=' . $name . '))',
249249
['perunGroupId', 'cn', 'perunUniqueGroupName', 'perunVoId', 'uuid', 'description']
250250
);
251-
if (null === $group) {
251+
if ($group === null) {
252252
throw new Exception('Group with name: $name in VO: ' . $vo->getName() . ' does not exists in Perun LDAP.');
253253
}
254254

@@ -269,7 +269,7 @@ public function getVoByShortName($voShortName)
269269
'(&(objectClass=perunVo)(o=' . $voShortName . '))',
270270
['perunVoId', 'o', 'description']
271271
);
272-
if (null === $vo) {
272+
if ($vo === null) {
273273
throw new Exception('Vo with name: ' . $voShortName . ' does not exists in Perun LDAP.');
274274
}
275275

@@ -284,7 +284,7 @@ public function getVoById($id)
284284
['o', 'description']
285285
);
286286

287-
if (null === $vo) {
287+
if ($vo === null) {
288288
throw new Exception('Vo with id: ' . $id . ' does not exists in Perun LDAP.');
289289
}
290290

@@ -480,7 +480,7 @@ public function getUsersGroupsOnFacility($spEntityId, $userId)
480480

481481
public function getUsersGroupsOnSp($facility, $userId)
482482
{
483-
if (null === $facility) {
483+
if ($facility === null) {
484484
return [];
485485
}
486486
$id = $facility->getId();
@@ -492,7 +492,7 @@ public function getUsersGroupsOnSp($facility, $userId)
492492
);
493493
Logger::debug('Resources - ' . json_encode($resources));
494494

495-
if (null === $resources) {
495+
if ($resources === null) {
496496
throw new Exception('Service with ID: ' . $id . ' hasn\'t assigned any resource.');
497497
}
498498
$resourcesString = '(|';
@@ -551,20 +551,20 @@ public function isUserInVo($user, $voShortName)
551551
}
552552

553553
$vo = $this->getVoByShortName($voShortName);
554-
if (null === $vo) {
554+
if ($vo === null) {
555555
Logger::debug('isUserInVo - No VO found, returning false');
556556

557557
return false;
558558
}
559559

560-
return Member::VALID === $this->getMemberStatusByUserAndVo($user, $vo);
560+
return $this->getMemberStatusByUserAndVo($user, $vo) === Member::VALID;
561561
}
562562

563563
public function getResourceCapabilities($entityId, $userGroups)
564564
{
565565
$facility = $this->getFacilityByEntityId($entityId);
566566

567-
if (null === $facility) {
567+
if ($facility === null) {
568568
return [];
569569
}
570570

@@ -620,7 +620,7 @@ public function getFacilityCapabilities($entityId)
620620

621621
private function mapUser($user)
622622
{
623-
if (null === $user) {
623+
if ($user === null) {
624624
return null;
625625
}
626626
if (isset($user['displayName'][0])) {
@@ -637,19 +637,19 @@ private function mapUser($user)
637637
private function resolveAttrValue($attrsNameTypeMap, $attrsFromLdap, $attr)
638638
{
639639
if (!array_key_exists($attr, $attrsFromLdap)) {
640-
if (self::TYPE_BOOL === $attrsNameTypeMap[$attr][self::TYPE]) {
640+
if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_BOOL) {
641641
return false;
642642
}
643-
if (self::TYPE_MAP === $attrsNameTypeMap[$attr][self::TYPE]
644-
|| self::TYPE_DICTIONARY === $attrsNameTypeMap[$attr][self::TYPE]
643+
if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP
644+
|| $attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_DICTIONARY
645645
) {
646646
return [];
647647
}
648648
} else {
649-
if (self::TYPE_MAP === $attrsNameTypeMap[$attr][self::TYPE]) {
649+
if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP) {
650650
return $attrsFromLdap[$attr];
651651
}
652-
if (self::TYPE_DICTIONARY === $attrsNameTypeMap[$attr][self::TYPE]) {
652+
if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_DICTIONARY) {
653653
return $this->convertToMap($attrsFromLdap[$attr]);
654654
}
655655

lib/AdapterRpc.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class AdapterRpc extends Adapter
5454

5555
public function __construct($configFileName = null)
5656
{
57-
if (null === $configFileName) {
57+
if ($configFileName === null) {
5858
$configFileName = self::DEFAULT_CONFIG_FILE_NAME;
5959
}
6060

@@ -98,10 +98,10 @@ public function getPerunUser($idpEntityId, $uids)
9898

9999
return new User($user['id'], $name);
100100
} catch (PerunException $e) {
101-
if ('UserExtSourceNotExistsException' === $e->getName()) {
101+
if ($e->getName() === 'UserExtSourceNotExistsException') {
102102
continue;
103103
}
104-
if ('ExtSourceNotExistsException' === $e->getName()) {
104+
if ($e->getName() === 'ExtSourceNotExistsException') {
105105
// Because use of original/source entityID as extSourceName
106106
continue;
107107
}
@@ -205,7 +205,7 @@ public function getSpGroups(string $spEntityId): array
205205
{
206206
$facility = $this->getFacilityByEntityId($spEntityId);
207207

208-
if (null === $facility) {
208+
if ($facility === null) {
209209
return [];
210210
}
211211

@@ -394,7 +394,7 @@ public function getUsersGroupsOnFacility($spEntityId, $userId)
394394

395395
public function getUsersGroupsOnSp($facility, $userId)
396396
{
397-
if (null === $facility) {
397+
if ($facility === null) {
398398
return [];
399399
}
400400

@@ -412,7 +412,7 @@ public function getUsersGroupsOnSp($facility, $userId)
412412

413413
foreach ($usersGroupsOnFacility as $usersGroupOnFacility) {
414414
if (isset($usersGroupOnFacility['attributes'][0]['friendlyName']) &&
415-
'voShortName' === $usersGroupOnFacility['attributes'][0]['friendlyName']) {
415+
$usersGroupOnFacility['attributes'][0]['friendlyName'] === 'voShortName') {
416416
$uniqueName = $usersGroupOnFacility['attributes'][0]['value'] . ':' . $usersGroupOnFacility['name'];
417417

418418
array_push($groups, new Group(
@@ -503,7 +503,7 @@ public function getMemberByUser($user, $vo)
503503
'user' => $user->getId(),
504504
'vo' => $vo->getId(),
505505
]);
506-
if (null === $member) {
506+
if ($member === null) {
507507
throw new Exception(
508508
'Member for User with name ' . $user->getName() . ' and Vo with shortName ' . $vo->getShortName() . 'does not exist in Perun!'
509509
);
@@ -522,13 +522,13 @@ public function isUserInVo($user, $voShortName)
522522
}
523523

524524
$vo = $this->getVoByShortName($voShortName);
525-
if (null === $vo) {
525+
if ($vo === null) {
526526
Logger::debug('isUserInVo - No VO found, returning false');
527527

528528
return false;
529529
}
530530

531-
return Member::VALID === $this->getMemberStatusByUserAndVo($user, $vo);
531+
return $this->getMemberStatusByUserAndVo($user, $vo) === Member::VALID;
532532
}
533533

534534
/**
@@ -653,7 +653,7 @@ public function getResourceCapabilities($entityId, $userGroups)
653653
{
654654
$facility = $this->getFacilityByEntityId($entityId);
655655

656-
if (null === $facility) {
656+
if ($facility === null) {
657657
return [];
658658
}
659659

@@ -677,7 +677,7 @@ public function getResourceCapabilities($entityId, $userGroups)
677677
'attributeName' => 'urn:perun:resource:attribute-def:def:capabilities',
678678
])['value'];
679679

680-
if (null === $resourceCapabilities) {
680+
if ($resourceCapabilities === null) {
681681
continue;
682682
}
683683

@@ -698,7 +698,7 @@ public function getFacilityCapabilities($entityId)
698698
{
699699
$facility = $this->getFacilityByEntityId($entityId);
700700

701-
if (null === $facility) {
701+
if ($facility === null) {
702702
return [];
703703
}
704704

lib/AttributeUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private static function getConfig()
127127
Logger::warning('perun:AttributeUtils: missing or invalid perun_attributes.php config file');
128128
}
129129

130-
if (null === $perunAttributesConfig) {
130+
if ($perunAttributesConfig === null) {
131131
throw new Exception('perun:AttributeUtils: missing or invalid perun_attributes.php config file');
132132
}
133133

0 commit comments

Comments
 (0)