Skip to content

Commit cfc12f5

Browse files
committed
Refactor docker container to be able to run any PHP version from 7.4
Thanks AI for 😄: - update Dockerfile - update docker-compose - create Makefile Update code with: - CS Fixer - Rector
1 parent a465bac commit cfc12f5

13 files changed

Lines changed: 129 additions & 17 deletions

.docker/Dockerfile

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1-
FROM splitbrain/phpfarm:jessie
1+
FROM debian:trixie-slim
22

3-
RUN apt-get update && apt-get install -y git zip
3+
# Prevent interactive prompts
4+
ENV DEBIAN_FRONTEND=noninteractive
45

6+
# Install dependencies
7+
RUN apt-get update && apt-get install -y \
8+
apt-transport-https \
9+
ca-certificates \
10+
curl \
11+
git \
12+
lsb-release \
13+
unzip \
14+
zip \
15+
&& curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \
16+
&& echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
17+
&& apt-get update
18+
19+
# Supported PHP Versions
20+
ENV PHP_VERSIONS="7.4 8.0 8.1 8.2 8.3 8.4 8.5"
21+
22+
# Install all PHP versions using a loop
23+
RUN for ver in $PHP_VERSIONS; do \
24+
apt-get install -y \
25+
php${ver}-cli php${ver}-xml php${ver}-mbstring php${ver}-soap; \
26+
done \
27+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
28+
29+
# Create symlinks (php-X.Y) using the same list
30+
RUN for ver in $PHP_VERSIONS; do \
31+
ln -s /usr/bin/php${ver} /usr/bin/php-${ver}; \
32+
done
33+
34+
# Install Composer
535
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
36+
37+
# Set working directory
38+
WORKDIR /var/www
39+
40+
# Copy project files
641
COPY . /var/www/
742

8-
WORKDIR /var/www/
43+
# Default command
44+
CMD ["bash"]

.github/workflows/sonars.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- release/*
99
pull_request:
1010
types: [ opened, synchronize, reopened ]
11+
concurrency: sonars
1112
jobs:
1213
sonarcloud:
1314
name: Sonars
@@ -42,7 +43,7 @@ jobs:
4243
run: sed -i 's@'$GITHUB_WORKSPACE/'@''@g' coverage.xml report.xml
4344

4445
- name: SonarCloud Scan
45-
uses: SonarSource/sonarcloud-github-action@master
46+
uses: SonarSource/sonarqube-scan-action@v7
4647
env:
4748
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4849
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule ".docker"]
2+
path = .docker
3+
url = git@github.com:WsdlToPhp/DockerCommonImage.git

.php-cs-fixer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
'no_whitespace_in_blank_line' => true,
1616
'ternary_operator_spaces' => true,
1717
'cast_spaces' => true,
18-
'trailing_comma_in_multiline' => true
18+
'trailing_comma_in_multiline' => true,
19+
'phpdoc_separation' => false,
20+
'single_line_empty_body' => false,
1921
))
2022
->setFinder($finder);

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
PHP_VERSION ?= php-7.4
2+
CONTAINER_NAME ?= package_base
3+
COMPOSER ?= /usr/bin/composer
4+
DOCKER_COMPOSE ?= docker compose
5+
DOCKER_EXEC_CONTAINER ?= docker exec -t $(CONTAINER_NAME)
6+
7+
.PHONY: bash build cs-fixer down install phpstan phpunit rector up update
8+
9+
bash:
10+
$(DOCKER_EXEC_CONTAINER) bash
11+
12+
build:
13+
$(DOCKER_COMPOSE) build
14+
15+
cs-fixer:
16+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/php-cs-fixer fix --ansi --diff --verbose
17+
18+
down:
19+
$(DOCKER_COMPOSE) down
20+
21+
install:
22+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) install
23+
24+
phpstan:
25+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpstan analyze src --level=2
26+
27+
phpunit:
28+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpunit
29+
30+
rector:
31+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/rector process
32+
33+
up:
34+
$(DOCKER_COMPOSE) up -d
35+
36+
update:
37+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) update

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@
6969
"phpstan": "vendor/bin/phpstan analyze src --level=5"
7070
},
7171
"require-dev": {
72-
"friendsofphp/php-cs-fixer": "~3.0",
73-
"phpstan/phpstan": "^1.4",
74-
"phpunit/phpunit": "^9"
72+
"friendsofphp/php-cs-fixer": "^3.0",
73+
"phpstan/phpstan": "^2",
74+
"phpunit/phpunit": "^9",
75+
"rector/rector": "^2"
7576
},
7677
"autoload": {
7778
"psr-4": {

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.4'
2-
31
services:
42
php:
53
build:
@@ -8,3 +6,4 @@ services:
86
volumes:
97
- .:/var/www:rw
108
container_name: package_base
9+
tty: true

rector.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
9+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
10+
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->paths([
13+
__DIR__.'/src',
14+
__DIR__.'/tests',
15+
]);
16+
$rectorConfig->skip([
17+
__DIR__.'/tests/resources',
18+
]);
19+
// define sets of rules
20+
$rectorConfig->sets([
21+
LevelSetList::UP_TO_PHP_74,
22+
]);
23+
24+
// replace fully qualified class name by use statements
25+
$rectorConfig->importShortClasses(false);
26+
// keep native PHP class short name import
27+
$rectorConfig->importNames();
28+
29+
// register a single rule
30+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
31+
$rectorConfig->rule(ReturnTypeFromStrictNativeCallRector::class);
32+
$rectorConfig->rule(ReturnTypeFromStrictTypedPropertyRector::class);
33+
};

src/AbstractSoapClientBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,6 @@ public function getOutputHeaders(): array
447447
*/
448448
public function __toString(): string
449449
{
450-
return get_called_class();
450+
return static::class;
451451
}
452452
}

src/AbstractStructBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function jsonSerialize(): array
2727
*/
2828
public static function __set_state(array $array): StructInterface
2929
{
30-
$reflection = new ReflectionClass(get_called_class());
30+
$reflection = new ReflectionClass(static::class);
3131
$object = $reflection->newInstance();
3232
foreach ($array as $name => $value) {
3333
$object->setPropertyValue($name, $value);
@@ -79,6 +79,6 @@ public function getPropertyValue(string $name)
7979
*/
8080
public function __toString(): string
8181
{
82-
return get_called_class();
82+
return static::class;
8383
}
8484
}

0 commit comments

Comments
 (0)