Skip to content

Commit 91526a1

Browse files
authored
improve formatters (#459)
1 parent baae660 commit 91526a1

File tree

11 files changed

+88
-32
lines changed

11 files changed

+88
-32
lines changed

.phpcs-ruleset-impure.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Unity">
3+
<description>PSR12, with no max line length</description>
4+
<rule ref="PSR12" />
5+
<rule ref="Generic.Files.LineLength">
6+
<exclude name="Generic.Files.LineLength" />
7+
</rule>
8+
</ruleset>

.phpcs-ruleset-pure.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Unity">
3+
<description>
4+
PSR12,
5+
with max line length = 100 characters,
6+
should play nice with prettier/plugin-php
7+
allows multiple classes in one file
8+
</description>
9+
<rule ref="PSR12" />
10+
<rule ref="Generic.Files.LineLength">
11+
<properties>
12+
<property name="lineLimit" value="100" />
13+
<property name="absoluteLineLimit" value="100" />
14+
</properties>
15+
</rule>
16+
<rule ref="PSR2.Classes.ClassDeclaration.OpenBraceNewLine">
17+
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
18+
</rule>
19+
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore">
20+
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore" />
21+
</rule>
22+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
23+
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
24+
</rule>
25+
</ruleset>

.phpcs-ruleset.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,38 @@ repos:
1616

1717
- repo: local
1818
hooks:
19-
- id: phpcbf
20-
name: PHP Code Beautifier and Fixer
19+
- id: phpcbf-pure
20+
name: PHP Code Beautifier and Fixer (pure PHP files)
2121
entry: ./vendor/bin/phpcbf
22-
args: [--standard=./.phpcs-ruleset.xml, --colors]
22+
args: [--standard=./.phpcs-ruleset-pure.xml, --colors]
2323
language: system
2424
files: \.php$
25-
# exclude pure PHP files
2625
exclude: |
2726
(?x)^(
2827
test/.*|
2928
workers/.*|
3029
node_modules/.*|
3130
resources/lib/phpopenldaper/.*|
3231
vendor/.*|
33-
resources/lib/.*|
32+
resources/templates/.*|
33+
resources/mail/.*|
34+
webroot/.*|
35+
)$
36+
- id: phpcbf-impure
37+
name: PHP Code Beautifier and Fixer (mixed PHP/HTML files)
38+
entry: ./vendor/bin/phpcbf
39+
args: [--standard=./.phpcs-ruleset-impure.xml, --colors]
40+
language: system
41+
files: |
42+
(?x)^(
43+
resources/templates/.*\.php|
3444
resources/mail/.*|
45+
webroot/.*\.php|
46+
)$
47+
# the user_flag_* templates use funky syntax and the formatter ruins them
48+
exclude: |
49+
(?x)^(
50+
resources/mail/user_flag_.*\.php|
3551
)$
3652
3753
- repo: https://github.com/rbubley/mirrors-prettier
@@ -68,22 +84,38 @@ repos:
6884

6985
- repo: local
7086
hooks:
71-
- id: phpcs
72-
name: PHP CodeSniffer
87+
- id: phpcs-pure
88+
name: PHP Code Sniffer (pure PHP files)
7389
entry: ./vendor/bin/phpcs
90+
args: [--standard=./.phpcs-ruleset-pure.xml, --colors, -s]
7491
language: system
7592
files: \.php$
76-
args: [--standard=./.phpcs-ruleset.xml, --colors]
77-
# exclude pure PHP files
7893
exclude: |
7994
(?x)^(
8095
test/.*|
8196
workers/.*|
8297
node_modules/.*|
8398
resources/lib/phpopenldaper/.*|
8499
vendor/.*|
85-
resources/lib/.*|
100+
resources/templates/.*|
86101
resources/mail/.*|
102+
webroot/.*|
103+
)$
104+
- id: phpcs-impure
105+
name: PHP Code Sniffer (mixed PHP/HTML files)
106+
entry: ./vendor/bin/phpcs
107+
args: [--standard=./.phpcs-ruleset-impure.xml, --colors, -s]
108+
language: system
109+
files: |
110+
(?x)^(
111+
resources/templates/.*\.php|
112+
resources/mail/.*\.php|
113+
webroot/.*\.php|
114+
)$
115+
# the user_flag_* templates use funky syntax and the formatter ruins them
116+
exclude: |
117+
(?x)^(
118+
resources/mail/user_flag_.*\.php|
87119
)$
88120
- id: php-l
89121
name: php -l

resources/lib/CSRFToken.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace UnityWebPortal\lib;
34

45
class CSRFToken

resources/lib/PosixGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace UnityWebPortal\lib;
44

55
use PHPOpenLDAPer\LDAPEntry;
6-
use \Exception;
6+
use Exception;
77

88
/*
99
does not extend LDAPEntry because UnityGroup extends this and I don't want UnityGroup

resources/lib/UnityGithub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace UnityWebPortal\lib;
4+
45
use UnityWebPortal\lib\exceptions\CurlException;
56

67
class UnityGithub

resources/lib/UnityGroup.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
namespace UnityWebPortal\lib;
4-
use PHPOpenLDAPer\LDAPEntry;
54

5+
use PHPOpenLDAPer\LDAPEntry;
66
use Exception;
77

88
/**
@@ -85,7 +85,8 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true
8585
if ($send_mail) {
8686
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_created");
8787
}
88-
$this->getOwner()->setFlag(UserFlag::QUALIFIED, true); // having your own group makes you qualified
88+
// having your own group makes you qualified
89+
$this->getOwner()->setFlag(UserFlag::QUALIFIED, true);
8990
}
9091

9192
/**

resources/lib/UnityHTTPD.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public static function validatePostCSRFToken(): void
390390
self::errorLog("csrf failed to validate", "", errorid: $errorid);
391391
self::messageError(
392392
"Invalid Session Token",
393-
"This can happen if you leave your browser open for a long time. Error ID: $errorid",
393+
"This can happen if you leave your browser open for too long. Error ID: $errorid",
394394
);
395395
self::redirect();
396396
}

resources/lib/UnityLDAP.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,11 @@ public function getQualifiedUID2PIGIDs(): array
273273
$uids = $this->userFlagGroups[UserFlag::QUALIFIED->value]->getMemberUIDs();
274274
$uid2pigids = array_combine($uids, array_fill(0, count($uids), []));
275275
// for each PI group, append that GID to the member list for each of its member UIDs
276-
foreach (
277-
$this->getAllPIGroupsAttributes(
278-
["cn", "memberuid"],
279-
default_values: ["memberuid" => []],
280-
)
281-
as $array
282-
) {
276+
$pi_groups_attributes = $this->getAllPIGroupsAttributes(
277+
["cn", "memberuid"],
278+
default_values: ["memberuid" => []],
279+
);
280+
foreach ($pi_groups_attributes as $array) {
283281
$gid = $array["cn"][0];
284282
foreach ($array["memberuid"] as $uid) {
285283
if (array_key_exists($uid, $uid2pigids)) {

0 commit comments

Comments
 (0)