Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for base library v4 #3

Merged
merged 9 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .docker/Dockerfile.php81
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM php:8.1-cli

# Install dependencies
RUN apt update && \
apt upgrade -y && \
apt install -y \
git \
curl \
zip \
unzip

# Install Packages via PECL as not provided by PHP Source
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

# Clear cache
RUN apt clean && \
rm -rf /var/lib/apt/lists/*

# Install composer (get latest v2, change to `--1` if you want to install the latest v1).
RUN curl -sS https://getcomposer.org/installer | php -- --2 --install-dir=/usr/local/bin --filename=composer

COPY . /usr/src/lib
WORKDIR /usr/src/lib

CMD [ "php"]
26 changes: 26 additions & 0 deletions .docker/Dockerfile.php82
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM php:8.2-cli

# Install dependencies
RUN apt update && \
apt upgrade -y && \
apt install -y \
git \
curl \
zip \
unzip

# Install Packages via PECL as not provided by PHP Source
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

# Clear cache
RUN apt clean && \
rm -rf /var/lib/apt/lists/*

# Install composer (get latest v2, change to `--1` if you want to install the latest v1).
RUN curl -sS https://getcomposer.org/installer | php -- --2 --install-dir=/usr/local/bin --filename=composer

COPY . /usr/src/lib
WORKDIR /usr/src/lib

CMD [ "php"]
26 changes: 26 additions & 0 deletions .docker/Dockerfile.php83
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM php:8.3-cli

# Install dependencies
RUN apt update && \
apt upgrade -y && \
apt install -y \
git \
curl \
zip \
unzip

# Install Packages via PECL as not provided by PHP Source
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

# Clear cache
RUN apt clean && \
rm -rf /var/lib/apt/lists/*

# Install composer (get latest v2, change to `--1` if you want to install the latest v1).
RUN curl -sS https://getcomposer.org/installer | php -- --2 --install-dir=/usr/local/bin --filename=composer

COPY . /usr/src/lib
WORKDIR /usr/src/lib

CMD [ "php"]
47 changes: 47 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Workflow name
name: Static Analysis

# Triggers
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'

# Jobs/Pipelines
jobs:
phpstan:
name: 'PHP Stan'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ 8.1, 8.2, 8.3 ]
steps:
- name: "Checkout Code"
uses: actions/checkout@v4

- name: "Setup PHP with tools"
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer, phpstan

- name: "Get composer cache directory"
id: composer-cache
run: 'echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'

- name: "Cache dependencies"
uses: actions/cache@v4
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "${{ runner.os }}-php-${{ matrix.php}}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ runner.os }}-php-${{ matrix.php}}-composer-"

- name: "Install Composer dependencies"
run: composer install --no-ansi --no-interaction --no-progress --no-scripts --prefer-dist

- name: "Run PHPStan Static Analysis"
run: phpstan analyse
23 changes: 21 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/vendor/
# Composer
composer.lock
.php-cs-fixer.cache
vendor/

# Tools
.php-cs-fixer.cache
phpunit.xml
phpstan.neon
.phpunit.result.cache
.phpunit.cache/

# Docker
.docker/Dockerfile
docker-compose.yml

# IDE
.vscode/
.idea/

# System
.DS_Store
error_log
84 changes: 84 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
.PHONY: help

# List all available Makefile commands.
help:
@echo "Available commands:"
@echo " make help : List all available Makefile commands"
@echo " make setup-php81 : Start the dev environment with PHP 8.1"
@echo " make setup-php82 : Start the dev environment with PHP 8.2"
@echo " make setup-php83 : Start the dev environment with PHP 8.3"
@echo " make shell : Get an interactive shell on the PHP container"
@echo " make static-analysis : Run Static Analysis (PHPStan)"
@echo " make coding-standards : Run Coding Standards (PHP-CS-Fixer)"
@echo " make start-containers : Start the dev environment"
@echo " make stop-containers : Stop the dev environment"
@echo " make kill-containers : Stop and remove all containers"
@echo " make composer-install : Install composer dependencies"

# Typing 'make setup-php81' will start the dev environment with PHP 8.1
setup-php81: stop-containers --prep-dockerfile-php81 start-containers --remove-packages composer-install

# Typing 'make setup-php82' will start the dev environment with PHP 8.2
setup-php82: stop-containers --prep-dockerfile-php82 start-containers --remove-packages composer-install

# Typing 'make setup-php83' will start the dev environment with PHP 8.3
setup-php83: stop-containers --prep-dockerfile-php83 start-containers --remove-packages composer-install

# Get a shell on the PHP container
shell:
docker compose exec -it app /bin/bash

# Run Static Analysis (PHPStan)
static-analysis:
docker compose exec app ./vendor/bin/phpstan analyse --memory-limit=1G

coding-standards:
docker compose exec app php ./bin/php-cs-fixer-v3.phar fix --config=./.php-cs-fixer.dist.php

# Start the dev environment
start-containers:
docker compose up -d --build

# Stop the dev environment
stop-containers:
docker compose down

# Stop and remove all containers
kill-containers:
docker compose kill
docker compose rm --force

# Install composer dependencies
composer-install:
docker compose exec app composer install --no-interaction

# Copy Dockerfile for PHP 8.1
--prep-dockerfile-php81: --remove-dockerfile --prep-docker-compose-file
cp "./.docker/Dockerfile.php81" "./.docker/Dockerfile"

# Copy Dockerfile for PHP 8.2
--prep-dockerfile-php82: --remove-dockerfile --prep-docker-compose-file
cp "./.docker/Dockerfile.php82" "./.docker/Dockerfile"

# Copy Dockerfile for PHP 8.3
--prep-dockerfile-php83: --remove-dockerfile --prep-docker-compose-file
cp "./.docker/Dockerfile.php83" "./.docker/Dockerfile"

# Copy docker-compose.yml file
--prep-docker-compose-file:
[ -f "./docker-compose.yml" ] || cp "./docker-compose.yml.example" "./docker-compose.yml"

# Remove Dockerfile
--remove-dockerfile:
rm -f ./docker/Dockerfile

# Remove composer related files
--remove-packages: --remove-lockfile --remove-vendor

# Remove composer.lock file
--remove-lockfile:
docker compose exec app rm -f ./composer.lock

# Remove vendor directory
--remove-vendor:
docker compose exec app rm -rf ./vendor
Binary file renamed bin/php-cs-fixer → bin/php-cs-fixer-v3.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
}
],
"require": {
"upmind/provision-provider-base": "^3.0"
"php": "8.1 - 8.3",
"upmind/provision-provider-base": "^4.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.3'
services:

#PHP Service
app:
build:
context: .
dockerfile: ./.docker/Dockerfile
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /usr/src/lib
volumes:
- ./:/usr/src/lib
networks:
- app-network

#Docker Networks
networks:
app-network:
driver: bridge
1 change: 0 additions & 1 deletion fix_formatting.sh

This file was deleted.

4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 4
paths:
- src
2 changes: 1 addition & 1 deletion src/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class LaravelServiceProvider extends ProvisionServiceProvider
{
public function boot()
public function boot(): void
{
$this->bindCategory('seo', Category::class);

Expand Down
2 changes: 0 additions & 2 deletions src/Providers/Example/Data/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
* Example API credentials.
*
* @property-read string $api_token API token
* @property-read bool $debug Whether or not to log API requests and responses
*/
class Configuration extends DataSet
{
public static function rules(): Rules
{
return new Rules([
'api_token' => ['required', 'string'],
'debug' => ['boolean'],
]);
}
}
2 changes: 1 addition & 1 deletion src/Providers/Example/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function terminate(AccountIdentifierParams $params): EmptyResult
protected function client(): Client
{
return $this->client ??= new Client([
'handler' => $this->getGuzzleHandlerStack(boolval($this->configuration->debug)),
'handler' => $this->getGuzzleHandlerStack(),
'base_uri' => 'https://example.com/api/v1/',
'headers' => [
'Authorization' => 'Bearer ' . $this->configuration->api_token,
Expand Down
2 changes: 0 additions & 2 deletions src/Providers/Marketgoo/Data/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/**
* @property-read string $api_url URL of the marketgoo API
* @property-read string $api_key marketgoo API KEY for provision API
* @property-read bool|null $debug Whether or not to log all HTTP requests and responses
*/
class Configuration extends DataSet
{
Expand All @@ -19,7 +18,6 @@ public static function rules(): Rules
return new Rules([
'api_url' => ['required', 'string'],
'api_key' => ['required', 'string'],
'debug' => ['boolean'],
]);
}
}
2 changes: 1 addition & 1 deletion src/Providers/Marketgoo/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function client(): Client

return new Client([
'base_uri' => rtrim($apiUrl, '/') . '/api/',
'handler' => $this->getGuzzleHandlerStack(!!$this->configuration->debug),
'handler' => $this->getGuzzleHandlerStack(),
RequestOptions::HTTP_ERRORS => false,
RequestOptions::HEADERS => [
'Accept' => 'application/vnd.marketgoo.api+json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractHandler
/**
* Parsed response body data.
*
* @var array|null $data
* @var array<string, mixed>|null $data
*/
protected $data;

Expand Down
4 changes: 0 additions & 4 deletions src/Providers/Marketgoo/ResponseHandlers/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ public function assertSuccess(string $name = 'operation'): void
switch ($this->response->getStatusCode()) {
case 400:
throw new CannotParseResponse($this->parseError('Invalid parameters'));
break;
case 403:
throw new CannotParseResponse($this->parseError('API authentication not valid!'));
break;
case 404:
throw new CannotParseResponse($this->parseError('Account not found!'));
break;
case 409:
throw new CannotParseResponse($this->parseError('Conflict!'));
break;
default:
throw new CannotParseResponse($this->parseError("Failed to {$name} account"));
}
Expand Down