Skip to content

Commit e485ec4

Browse files
authored
Local build: rely only on docker (#58)
1 parent aff7d78 commit e485ec4

20 files changed

+136
-71
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/.gitattributes export-ignore
44
/.gitignore export-ignore
55
/.php-cs-fixer.php export-ignore
6+
/Dockerfile export-ignore
7+
/docker-compose.yml export-ignore
68
/Makefile export-ignore
79
/composer-require-checker.json export-ignore
810
/phpstan.neon export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/.phpunit.cache/
33
/vendor/
44
/coverage/
5+
/.env
56
/.php-cs-fixer.cache
67
/.phpunit.result.cache
78
/composer.lock

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:8.3
2+
3+
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
4+
5+
RUN install-php-extensions @composer pcov
6+
7+
ARG USER_ID
8+
ARG GROUP_ID
9+
10+
RUN groupadd --gid ${GROUP_ID} code \
11+
&& useradd --create-home --shell /bin/bash --uid ${USER_ID} --gid code code
12+
13+
USER code

Makefile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
CSFIX_PHP_BIN=PHP_CS_FIXER_IGNORE_ENV=1 php8.2
2-
PHP_BIN=php8.2 -d zend.assertions=1
3-
COMPOSER_BIN=$(shell command -v composer)
1+
DOCKER_PHP_EXEC := docker compose run php
2+
PHP_BIN=php -d zend.assertions=1
43

54
all: csfix static-analysis test
65
@echo "Done."
76

8-
vendor: composer.json
9-
$(PHP_BIN) $(COMPOSER_BIN) update
10-
$(PHP_BIN) $(COMPOSER_BIN) bump
11-
touch vendor
7+
.env: /etc/passwd /etc/group Makefile
8+
printf "USER_ID=%s\nGROUP_ID=%s\n" `id --user "${USER}"` `id --group "${USER}"` > .env
9+
10+
vendor: .env docker-compose.yml Dockerfile composer.json
11+
docker compose build --pull
12+
$(DOCKER_PHP_EXEC) composer update
13+
$(DOCKER_PHP_EXEC) composer bump
14+
touch --no-create $@
1215

1316
.PHONY: csfix
1417
csfix: vendor
15-
$(CSFIX_PHP_BIN) vendor/bin/php-cs-fixer fix -v $(arg)
18+
$(DOCKER_PHP_EXEC) vendor/bin/php-cs-fixer fix -v $(arg)
1619

1720
.PHONY: static-analysis
1821
static-analysis: vendor
19-
$(PHP_BIN) vendor/bin/phpstan analyse $(PHPSTAN_ARGS)
22+
$(DOCKER_PHP_EXEC) $(PHP_BIN) vendor/bin/phpstan analyse --memory-limit=512M $(PHPSTAN_ARGS)
2023

2124
.PHONY: test
2225
test: vendor
23-
$(PHP_BIN) vendor/bin/phpunit $(PHPUNIT_ARGS)
26+
$(DOCKER_PHP_EXEC) $(PHP_BIN) vendor/bin/phpunit $(PHPUNIT_ARGS)
27+
28+
.PHONY: clean
29+
clean:
30+
git clean -dfX

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
],
1313
"require": {
1414
"php": "~8.2.0 || ~8.3.0",
15-
"nikic/php-parser": "^4.18.0 || ^5.0.0",
16-
"phpstan/phpstan": "^1.10.59"
15+
"nikic/php-parser": "^4.19.1 || ^5.0.2",
16+
"phpstan/phpstan": "^1.11.4"
1717
},
1818
"require-dev": {
19-
"nette/di": "^3.2.1",
19+
"nette/di": "^3.2.2",
2020
"nette/neon": "^3.4.1",
21-
"phpstan/phpstan-phpunit": "^1.3.16",
22-
"phpunit/phpunit": "^11.0.4",
21+
"phpstan/phpstan-phpunit": "^1.4.0",
22+
"phpunit/phpunit": "^11.2.1",
2323
"slam/php-cs-fixer-extensions": "^3.10.0"
2424
},
2525
"autoload": {

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
php:
3+
build:
4+
context: .
5+
args:
6+
USER_ID: ${USER_ID}
7+
GROUP_ID: ${GROUP_ID}
8+
volumes:
9+
- .:${PWD}
10+
working_dir: ${PWD}

lib/AccessGlobalVariableWithinContextRule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Broker\Broker;
1111
use PHPStan\Rules\Rule;
12+
use PHPStan\Rules\RuleError;
13+
use PHPStan\Rules\RuleErrorBuilder;
1214

1315
/**
1416
* @implements Rule<Variable>
@@ -42,7 +44,7 @@ public function getNodeType(): string
4244
return Variable::class;
4345
}
4446

45-
/** @return string[] */
47+
/** @return list<RuleError> */
4648
public function processNode(Node $node, Scope $scope): array
4749
{
4850
if (! \is_string($node->name)) {
@@ -64,12 +66,12 @@ public function processNode(Node $node, Scope $scope): array
6466

6567
$modelBaseClassOrInterface = $this->broker->getClass($this->contextBaseClassOrInterface);
6668

67-
return [\sprintf(
69+
return [RuleErrorBuilder::message(\sprintf(
6870
'Class %s %s %s and uses $%s: accessing globals in this context is considered an anti-pattern',
6971
$classReflection->getDisplayName(),
7072
$modelBaseClassOrInterface->isInterface() ? 'implements' : 'extends',
7173
$this->contextBaseClassOrInterface,
7274
$node->name
73-
)];
75+
))->identifier('globalAccess.outOfContext')->build()];
7476
}
7577
}

lib/AccessStaticPropertyWithinModelContextRule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Broker\Broker;
1111
use PHPStan\Rules\Rule;
12+
use PHPStan\Rules\RuleError;
13+
use PHPStan\Rules\RuleErrorBuilder;
1214

1315
/**
1416
* @implements Rule<StaticPropertyFetch>
@@ -31,7 +33,7 @@ public function getNodeType(): string
3133
return StaticPropertyFetch::class;
3234
}
3335

34-
/** @return string[] */
36+
/** @return list<RuleError> */
3537
public function processNode(Node $node, Scope $scope): array
3638
{
3739
if (! $node->class instanceof Node\Name || ! $node->name instanceof Node\VarLikeIdentifier) {
@@ -59,13 +61,13 @@ public function processNode(Node $node, Scope $scope): array
5961

6062
$modelBaseClassOrInterface = $this->broker->getClass($this->modelBaseClassOrInterface);
6163

62-
return [\sprintf(
64+
return [RuleErrorBuilder::message(\sprintf(
6365
'Class %s %s %s and uses %s::$%s: accessing a singleton in this context is considered an anti-pattern',
6466
$classReflection->getDisplayName(),
6567
$modelBaseClassOrInterface->isInterface() ? 'implements' : 'extends',
6668
$this->modelBaseClassOrInterface,
6769
$this->singletonAccessor,
6870
(string) $node->name
69-
)];
71+
))->identifier('singletonAccess.outOfContext')->build()];
7072
}
7173
}

lib/ClassNotationRule.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use PHPStan\Analyser\Scope;
1313
use PHPStan\Broker\Broker;
1414
use PHPStan\Rules\Rule;
15+
use PHPStan\Rules\RuleError;
16+
use PHPStan\Rules\RuleErrorBuilder;
1517

1618
/**
1719
* @implements Rule<ClassLike>
@@ -30,23 +32,23 @@ public function getNodeType(): string
3032
return ClassLike::class;
3133
}
3234

33-
/** @return string[] */
35+
/** @return list<RuleError> */
3436
public function processNode(Node $node, Scope $scope): array
3537
{
36-
$messages = [];
3738
$nodeIdentifier = $node->name;
3839
if (null === $nodeIdentifier) {
39-
return $messages;
40+
return [];
4041
}
4142
$name = $nodeIdentifier->name;
4243
if (\str_starts_with($name, 'AnonymousClass')) {
43-
return $messages;
44+
return [];
4445
}
4546
if (null === $node->namespacedName) {
46-
return $messages;
47+
return [];
4748
}
4849

49-
$fqcn = $node->namespacedName->toString();
50+
$messages = [];
51+
$fqcn = $node->namespacedName->toString();
5052
if ($node instanceof Interface_) {
5153
if (! \preg_match('/Interface$/', $name)) {
5254
$messages[] = \sprintf('Interface %s should end with "Interface" suffix.', $fqcn);
@@ -75,6 +77,8 @@ public function processNode(Node $node, Scope $scope): array
7577
}
7678
}
7779

78-
return $messages;
80+
return \array_map(static function (string $message): RuleError {
81+
return RuleErrorBuilder::message($message)->identifier('classNotation')->build();
82+
}, $messages);
7983
}
8084
}

lib/GotoRule.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use PhpParser\Node\Stmt\Goto_;
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Rules\Rule;
11+
use PHPStan\Rules\RuleError;
12+
use PHPStan\Rules\RuleErrorBuilder;
1113

1214
/**
1315
* @implements Rule<Goto_>
@@ -19,9 +21,9 @@ public function getNodeType(): string
1921
return Goto_::class;
2022
}
2123

22-
/** @return string[] */
24+
/** @return list<RuleError> */
2325
public function processNode(Node $node, Scope $scope): array
2426
{
25-
return ['No goto, cmon!'];
27+
return [RuleErrorBuilder::message('No goto, cmon!')->identifier('goto.forbidden')->build()];
2628
}
2729
}

0 commit comments

Comments
 (0)