diff --git a/.docker/Dockerfile b/.docker/Dockerfile index ab0f992..14cda03 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -1,8 +1,44 @@ -FROM splitbrain/phpfarm:jessie +FROM debian:trixie-slim -RUN apt-get update && apt-get install -y git zip +# Prevent interactive prompts +ENV DEBIAN_FRONTEND=noninteractive +# Install dependencies +RUN apt-get update && apt-get install -y \ + apt-transport-https \ + ca-certificates \ + curl \ + git \ + lsb-release \ + unzip \ + zip \ + && curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \ + && 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 \ + && apt-get update + +# Supported PHP Versions +ENV PHP_VERSIONS="7.4 8.0 8.1 8.2 8.3 8.4 8.5" + +# Install all PHP versions using a loop +RUN for ver in $PHP_VERSIONS; do \ + apt-get install -y \ + php${ver}-cli php${ver}-xml php${ver}-mbstring php${ver}-soap; \ + done \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Create symlinks (php-X.Y) using the same list +RUN for ver in $PHP_VERSIONS; do \ + ln -s /usr/bin/php${ver} /usr/bin/php-${ver}; \ + done + +# Install Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Set working directory +WORKDIR /var/www + +# Copy project files COPY . /var/www/ -WORKDIR /var/www/ +# Default command +CMD ["bash"] diff --git a/.github/workflows/sonars.yml b/.github/workflows/sonars.yml index b8f9453..da86577 100644 --- a/.github/workflows/sonars.yml +++ b/.github/workflows/sonars.yml @@ -8,6 +8,7 @@ on: - release/* pull_request: types: [ opened, synchronize, reopened ] +concurrency: sonars jobs: sonarcloud: name: Sonars @@ -42,7 +43,7 @@ jobs: run: sed -i 's@'$GITHUB_WORKSPACE/'@''@g' coverage.xml report.xml - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + uses: SonarSource/sonarqube-scan-action@v7 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a4044cb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".docker"] + path = .docker + url = git@github.com:WsdlToPhp/DockerCommonImage.git diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index a83abe0..05152c0 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -15,6 +15,8 @@ 'no_whitespace_in_blank_line' => true, 'ternary_operator_spaces' => true, 'cast_spaces' => true, - 'trailing_comma_in_multiline' => true + 'trailing_comma_in_multiline' => true, + 'phpdoc_separation' => false, + 'single_line_empty_body' => false, )) ->setFinder($finder); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..de1215b --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +PHP_VERSION ?= php-7.4 +CONTAINER_NAME ?= package_base +COMPOSER ?= /usr/bin/composer +DOCKER_COMPOSE ?= docker compose +DOCKER_EXEC_CONTAINER ?= docker exec -t $(CONTAINER_NAME) + +.PHONY: bash build cs-fixer down install phpstan phpunit rector up update + +bash: + $(DOCKER_EXEC_CONTAINER) bash + +build: + $(DOCKER_COMPOSE) build + +cs-fixer: + $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/php-cs-fixer fix --ansi --diff --verbose + +down: + $(DOCKER_COMPOSE) down + +install: + $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) install + +phpstan: + $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpstan analyze src --level=2 + +phpunit: + $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpunit + +rector: + $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/rector process + +up: + $(DOCKER_COMPOSE) up -d + +update: + $(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) update diff --git a/composer.json b/composer.json index 9d3d058..df71b32 100644 --- a/composer.json +++ b/composer.json @@ -69,9 +69,10 @@ "phpstan": "vendor/bin/phpstan analyze src --level=5" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~3.0", - "phpstan/phpstan": "^1.4", - "phpunit/phpunit": "^9" + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^2", + "phpunit/phpunit": "^9", + "rector/rector": "^2" }, "autoload": { "psr-4": { diff --git a/docker-compose.yml b/docker-compose.yml index 611090c..1c3dcf7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.4' - services: php: build: @@ -8,3 +6,4 @@ services: volumes: - .:/var/www:rw container_name: package_base + tty: true diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..0d2ff4f --- /dev/null +++ b/rector.php @@ -0,0 +1,35 @@ +paths([ + __DIR__.'/src', + __DIR__.'/tests', + ]); + $rectorConfig->skip([ + __DIR__.'/tests/resources', + ]); + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_74, + ]); + + // replace fully qualified class name by use statements + $rectorConfig->importShortClasses(false); + // keep native PHP class short name import + $rectorConfig->importNames(); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + $rectorConfig->rule(ReturnTypeFromStrictNativeCallRector::class); + $rectorConfig->rule(ReturnTypeFromStrictTypedPropertyRector::class); + $rectorConfig->rule(ExplicitNullableParamTypeRector::class); +}; diff --git a/src/AbstractSoapClientBase.php b/src/AbstractSoapClientBase.php index accac03..801a5a3 100644 --- a/src/AbstractSoapClientBase.php +++ b/src/AbstractSoapClientBase.php @@ -447,6 +447,6 @@ public function getOutputHeaders(): array */ public function __toString(): string { - return get_called_class(); + return static::class; } } diff --git a/src/AbstractStructBase.php b/src/AbstractStructBase.php index 331bfac..6d1980b 100644 --- a/src/AbstractStructBase.php +++ b/src/AbstractStructBase.php @@ -27,7 +27,7 @@ public function jsonSerialize(): array */ public static function __set_state(array $array): StructInterface { - $reflection = new ReflectionClass(get_called_class()); + $reflection = new ReflectionClass(static::class); $object = $reflection->newInstance(); foreach ($array as $name => $value) { $object->setPropertyValue($name, $value); @@ -79,6 +79,6 @@ public function getPropertyValue(string $name) */ public function __toString(): string { - return get_called_class(); + return static::class; } } diff --git a/src/AbstractStructEnumBase.php b/src/AbstractStructEnumBase.php index bc6f569..acd4825 100644 --- a/src/AbstractStructEnumBase.php +++ b/src/AbstractStructEnumBase.php @@ -22,6 +22,6 @@ public static function valueIsValid($value): bool */ public function __toString(): string { - return get_called_class(); + return static::class; } } diff --git a/tests/CustomSoapClientService.php b/tests/CustomSoapClientService.php index 7438fdd..e018a81 100644 --- a/tests/CustomSoapClientService.php +++ b/tests/CustomSoapClientService.php @@ -10,7 +10,7 @@ * Services can specify a custom SoapClient class * to be used instead of PHP default by overriding * the constant below. - * + * * @see \WsdlToPhp\PackageBase\SoapClientInterface * @see \WsdlToPhp\PackageBase\AbstractSoapClientBase :: getSoapClientClassName() */ @@ -22,5 +22,5 @@ class CustomSoapClientService extends AbstractSoapClientBase * Custom SoapClient class used for current service. */ const DEFAULT_SOAP_CLIENT_CLASS = Client::class; - + } diff --git a/tests/SoapClientTest.php b/tests/SoapClientTest.php index 579d711..5a9d526 100755 --- a/tests/SoapClientTest.php +++ b/tests/SoapClientTest.php @@ -28,7 +28,7 @@ public function testSoapClientNameDefault(): void public function testCustomSoapClientNameReadFromConstant() { $defaultService = new DefaultSoapClientService(); - $customService = new CustomSoapClientService(); + $customService = new CustomSoapClientService(); $this->assertSame(SoapClientBase::class, $defaultService->getSoapClientClassName()); $this->assertSame(Client::class, $customService->getSoapClientClassName());