Skip to content

Commit

Permalink
Use native union types (#102)
Browse files Browse the repository at this point in the history
* Use native union types

* Use PHP 8 for PHP workflow

* Update CI configuration

* Remove old tests

* update release workflow

* feat!: Require Symfony 6 / PHP 8.1

* Test in Symfony 6 & 7

* Fix to php -v

* Testing lock GitHub action to Symfony 6/7

* Exclude PHP 8.1 & Symfony 7

* test
  • Loading branch information
simonrjones authored Jun 24, 2024
1 parent 143b782 commit c6a7430
Show file tree
Hide file tree
Showing 30 changed files with 93 additions and 1,228 deletions.
44 changes: 25 additions & 19 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,60 @@ name: PHP tests

on:
push:
branches: [ main ]
branches:
- main
- release/**
pull_request:
branches: [ main ]
branches:
- main

jobs:
build:

strategy:
matrix:
php-versions: ['7.4']
php: ['8.1', '8.2', '8.3']
symfony: ['6.4', '7.1']
exclude:
- php: '8.1'
symfony: '7.1'

runs-on: ubuntu-latest

name: On PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}

steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

# https://github.com/marketplace/actions/setup-php-action
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180

- uses: actions/checkout@v2

- name: Check PHP version
run: php -v

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress

- name: Code lint PHP files
run: ./vendor/bin/phplint
- name: Install Symfony ${{ matrix.symfony }} packages
run: |
composer update symfony/http-foundation:${{ matrix.symfony }}
composer update symfony/yaml:${{ matrix.symfony }}
- name: Lint PHP files
run: |
curl -Ls https://github.com/overtrue/phplint/releases/latest/download/phplint.phar -o /usr/local/bin/phplint
chmod +x /usr/local/bin/phplint
/usr/local/bin/phplint --no-cache --no-progress -v
- name: Coding standards
run: ./vendor/bin/phpcs
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/release-please.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: release-please

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
# Uses https://github.com/marketplace/actions/release-please-action
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
release-type: php
package-name: strata/frontend
62 changes: 20 additions & 42 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,49 @@
"authors": [
{
"name": "Simon Jones",
"email": "[email protected]",
"homepage": "https://studio24.net/",
"role": "Lead Developer"
},
{
"name": "Matt Buckland",
"homepage": "https://studio24.net/",
"role": "Developer"
},
{
"name": "Marie Manandise",
"homepage": "https://studio24.net/",
"role": "Developer"
"email": "[email protected]"
}
],
"require": {
"php": "^7.4|^8.0",
"friendsofsymfony/http-cache": "^2.12",
"psr/simple-cache": "^1.0",
"masterminds/html5": "2.*",
"monolog/monolog": "^2.0",
"strata/data": "^0.8",
"symfony/http-foundation": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0",
"toflar/psr6-symfony-http-cache-store": "^3.0"
"php": "^8.1",
"friendsofsymfony/http-cache": "^3.0",
"psr/simple-cache": "^3.0",
"masterminds/html5": "^2.9",
"strata/data": "dev-feature/php8",
"symfony/http-foundation": "^6.4|^7.1",
"symfony/yaml": "^6.4|^7.1",
"toflar/psr6-symfony-http-cache-store": "^4.0"
},
"autoload": {
"psr-4": {
"Strata\\Frontend\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.0",
"overtrue/phplint": "^3.0",
"phpunit/phpunit": "10.5",
"squizlabs/php_codesniffer": "^3.10",
"phpstan/phpstan": "^1.11",
"roave/security-advisories": "dev-latest",
"nyholm/psr7": "^1.5"
},
"scripts": {
"lint": [
"./vendor/bin/phplint"
],
"cs": [
"phpcs": [
"./vendor/bin/phpcs"
],
"fix": [
"phpcbf": [
"./vendor/bin/phpcbf"
],
"unit": [
"phpunit": [
"./vendor/bin/phpunit"
],
"phpstan": [
"./vendor/bin/phpstan analyse --memory-limit 512M"
],
"test": [
"composer lint",
"composer cs",
"composer unit"
"composer phpcs",
"composer phpunit"
]
},
"scripts-descriptions": {
"lint": "Lint PHP files",
"cs": "Test coding standards are met in PHP code",
"fix": "Fix PHP code so it meets coding standards",
"unit": "Run PHPUnit tests",
"test": "Run all tests (phplint, phpcs, phpunit)"
},
"config": {
"allow-plugins": false
}
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
parameters:
level: 1 # Move towards level 5 or 6
level: 2 # Move towards level 5 or 6
paths:
- src
- tests
excludePaths: # Exclude code which has yet to be refactored / removed
- src/Content/*
- src/Api/*
- src/Repository/RestApi/*
- src/Repository/WordPress/*
Expand Down
34 changes: 16 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/8.0/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true">
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="1"/>
</php>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
<exclude>
<directory>tests/Content</directory>
</exclude>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" colors="true">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="1"/>
</php>
<testsuites>
<testsuite name="Strata Frontend Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>

7 changes: 1 addition & 6 deletions src/Content/BaseContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Strata\Frontend\Content;

use Strata\Data\Helper\UnionTypes;
use Strata\Frontend\Content\Field\ContentFieldCollection;
use Strata\Frontend\Content\Field\ContentFieldInterface;
use Strata\Frontend\Content\Field\DateTime;
Expand Down Expand Up @@ -53,12 +52,8 @@ public function getId()
* @param string|int $id
* @return BaseContent
*/
public function setId($id): BaseContent
public function setId(string|int $id): BaseContent
{
if (!UnionTypes::is($id, 'string', 'int')) {
return $this;
}

$this->id = $id;
return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Query/WordPressQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class WordPressQuery extends Query
{
private string $fieldParameter = '_fields';
private string $resultsPerPageParam = 'per_page';
protected string $fieldParameter = '_fields';
protected string $resultsPerPageParam = 'per_page';

/**
* Pagination in headers:
Expand Down
5 changes: 1 addition & 4 deletions src/ResponseHelper/Psr7ResponseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Strata\Frontend\ResponseHelper;

use Psr\Http\Message\ResponseInterface;
use Strata\Data\Helper\UnionTypes;

/**
* Concrete implementation of response helper using PSR7 response objects
Expand All @@ -17,10 +16,8 @@ class Psr7ResponseHelper extends ResponseHelperAbstract
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function apply($response): ResponseInterface
public function apply(ResponseInterface $response): ResponseInterface
{
UnionTypes::assert('response', $response, ResponseInterface::class);

foreach ($this->getHeaders() as $name => $values) {
/** @var HeaderValue $header */
foreach ($values as $header) {
Expand Down
3 changes: 2 additions & 1 deletion src/ResponseHelper/ResponseHelperAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Strata\Frontend\ResponseHelper;

use FOS\HttpCache\ResponseTagger;
use Psr\Http\Message\ResponseInterface;
use Strata\Data\Cache\CacheLifetime;
use Strata\Data\Query\QueryManager;
use Strata\Frontend\Exception\InvalidResponseHeaderValueException;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function getHeaders(): array
/**
* @inheritDoc
*/
abstract public function apply($response);
abstract public function apply(ResponseInterface $response);

/**
* Add cache tags to response tagger from query manager
Expand Down
5 changes: 3 additions & 2 deletions src/ResponseHelper/ResponseHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Strata\Frontend\ResponseHelper;

use FOS\HttpCache\ResponseTagger;
use Psr\Http\Message\ResponseInterface;
use Strata\Data\Cache\CacheLifetime;
use Strata\Data\Query\QueryManager;
use Strata\Frontend\Exception\InvalidResponseHeaderValueException;
Expand All @@ -28,10 +29,10 @@ public function getHeaders(): array;

/**
* Apply headers to response object and return response
* @param $response
* @param ResponseInterface $response
* @return mixed
*/
public function apply($response);
public function apply(ResponseInterface $response);

/**
* Apply cache tags to response tagger from query manager
Expand Down
2 changes: 1 addition & 1 deletion src/View/ViewFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function stagingBanner($environment, $message = 'This is the <strong>%s</
if ($tests->isProd($environment, $prod)) {
return null;
} else {
$className = filter_var($environment, FILTER_SANITIZE_STRING);
$className = htmlspecialchars($environment);
$className = $helpers->slugify($className);
$message = sprintf($message, $environment);
return <<<EOD
Expand Down
Loading

0 comments on commit c6a7430

Please sign in to comment.