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

Add PHP >=8.1 compatibility #75

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: SecureHeaders
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
paths-ignore:
- 'docs/**'
- '*.md'

jobs:
test:
if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'ci skip')"
name: SecureHeaders (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
# env:
# DB_CHARSET: utf8
strategy:
fail-fast: false
matrix:
php-versions: ['8.1', '8.2']


steps:

- name: Checkout.
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2

- name: Install composer dependencies
run: composer install --prefer-dist --no-interaction

- name: Run tests
run: ./vendor/bin/phpunit

- name: Run PHP CS Fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ phpunit.xml
.DS_Store
.php_cs
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
39 changes: 39 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

$finder = (new \PhpCsFixer\Finder())
->in(__DIR__.'/src')
;

return (new \PhpCsFixer\Config())
->setRules([
'@PER-CS' => true,
'@PHP82Migration' => true,
'array_syntax' => ['syntax' => 'short'],

'braces_position' => [
'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end',
'anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end',
],
'new_with_parentheses' => [
'named_class' => false
],
'list_syntax' => [
'syntax' => 'long'
],
'trailing_comma_in_multiline' => [
'elements' => []
],
'control_structure_continuation_position' => [
'position' => 'next_line'
],
'concat_space' => [
'spacing' => 'none'
],
'single_line_empty_body' => false,
'not_operator_with_space' => true,
'return_type_declaration' => [
'space_before' => 'one',
],
])
->setFinder($finder)
;
26 changes: 0 additions & 26 deletions .php_cs.dist

This file was deleted.

14 changes: 4 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@
"Aidantwoods\\SecureHeaders\\": "src/"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/aidantwoods/PHP-CS-Fixer"
}
],
"suggest": {
"psr/http-message": "In case you want to use the PSR-7 adapter",
"aidantwoods/markdownphpdocs": "Install this on its own and add it to your path, to auto-generate documentation if contributing to this repo."
},
"require-dev": {
"friendsofphp/php-cs-fixer": "dev-feature/braces/position_after_return_type_hint",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4",
"psr/http-message": "^1.0",
"zendframework/zend-diactoros": "^1.0"
"friendsofphp/php-cs-fixer": "3.38.*",
"phpunit/phpunit": "10.4.*",
"psr/http-message": "1.1.*",
"zendframework/zend-diactoros": "1.3.*"
},
"autoload-dev": {
"psr-4": {
Expand Down
6 changes: 0 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite name="SecureHeaders Test Suite">
Expand Down
4 changes: 2 additions & 2 deletions src/Headers/AbstractHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function forEachAttribute(callable $callable)
*/
public function __toString()
{
return $this->name . ':' .($this->value === '' ? '' : ' ' . $this->value);
return $this->name.':'.($this->value === '' ? '' : ' '.$this->value);
}

/**
Expand All @@ -217,7 +217,7 @@ protected function parseAttributes()

$this->attributes[$type][] = [
'name' => $attrParts[0],
'value' => isset($attrParts[1]) ? $attrParts[1] : true
'value' => $attrParts[1] ?? true
];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Operations/CompileExpectCT.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function modify(HeaderBag &$headers)
*/
private function makeHeaderValue()
{
$pieces = ['max-age=' . (int) $this->config['max-age']];
$pieces = ['max-age='.(int) $this->config['max-age']];

if ($this->config['enforce'])
{
Expand All @@ -50,7 +50,7 @@ private function makeHeaderValue()

if ($this->config['report-uri'])
{
$pieces[] = 'report-uri="' . $this->config['report-uri'] . '"';
$pieces[] = 'report-uri="'.$this->config['report-uri'].'"';
}

return implode('; ', $pieces);
Expand Down
4 changes: 2 additions & 2 deletions src/Operations/CompileHPKP.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private function compile(array $config)
return '';
}

$maxAge = isset($config['max-age']) ? $config['max-age'] : 10;
$maxAge = $config['max-age'] ?? 10;

$pieces = ["max-age=$maxAge"];

Expand All @@ -99,7 +99,7 @@ private function compile(array $config)

if ($config['report-uri'])
{
$pieces[] = 'report-uri="' . $config['report-uri'] . '"';
$pieces[] = 'report-uri="'.$config['report-uri'].'"';
}

return implode('; ', $pieces);
Expand Down
2 changes: 1 addition & 1 deletion src/Operations/CompileHSTS.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function modify(HeaderBag &$headers)
*/
private function makeHeaderValue()
{
$pieces = ['max-age=' . $this->config['max-age']];
$pieces = ['max-age='.$this->config['max-age']];

if ($this->config['subdomains'])
{
Expand Down
8 changes: 4 additions & 4 deletions src/Operations/InjectStrictDynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class InjectStrictDynamic extends OperationWithErrors implements Operation, ExposesErrors
{
const ENFORCE = 0b01;
const REPORT = 0b10;
public const ENFORCE = 0b01;
public const REPORT = 0b10;

private $allowedCSPHashAlgs;
private $mode;
Expand Down Expand Up @@ -59,8 +59,8 @@ public function modify(HeaderBag &$HeaderBag)
$this->addError(
"<b>Strict-Mode</b> is enabled, but
<b>'strict-dynamic'</b> could not be added to <b>"
. $Header->getFriendlyName()
. '</b> because no hash or nonce was used.',
.$Header->getFriendlyName()
.'</b> because no hash or nonce was used.',
E_USER_WARNING
);
}
Expand Down