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

Refresh #1

Merged
merged 7 commits into from
Oct 5, 2023
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
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.github/ export-ignore
/features/ export-ignore
/tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/composer-require-checker.json export-ignore
/infection.json export-ignore
/phpcs.xml export-ignore
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml export-ignore
/psalm.xml export-ignore
84 changes: 84 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Check Build

on: [pull_request]

jobs:
build:

strategy:
matrix:
php: ["8.1", "8.2", "8.3"]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Prepare environment
run: |
echo "COMPOSER_CACHE=$(composer config cache-dir)" >> $GITHUB_ENV
mkdir -p ~/.ssh
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

- name: Composer Cache
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE }}
key: ${{ runner.os }}-composer

- name: Install dependencies
run: |
composer update --no-progress --no-interaction > /dev/null

- name: Check Dependencies
run: composer check-deps

- name: Check Code Style
run: PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check

- name: PHPStan
run: composer phpstan -- --no-progress

- name: Psalm
run: composer psalm

- name: Infection coverage of changed lines
if: "!contains(github.event.pull_request.labels.*.name, 'skip-infection')"
run: |
git fetch origin $GITHUB_BASE_REF $GITHUB_HEAD_REF
vendor/bin/infection \
--git-diff-base=origin/$GITHUB_BASE_REF \
--git-diff-lines \
--logger-github \
--min-msi=100 \
--min-covered-msi=100 \
--ignore-msi-with-no-mutations \
-jmax

- name: Save Infection result
uses: actions/upload-artifact@v3
if: always()
with:
name: infection-log-${{ matrix.php }}.txt
path: infection-log.txt

- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.xml --stop-on-failure

- name: Monitor coverage
if: github.event_name == 'pull_request'
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_path: "coverage.xml"
comment: false
comment_context: Coverage PHP ${{ matrix.php }}
status_context: Coverage PHP ${{ matrix.php }}
threshold_alert: 83
threshold_warning: 83
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/.phpstan.neon
.phpunit.result.cache
/.php-cs-fixer.cache
/composer.lock
/vendor/
/infection-log.txt
/vendor/
7 changes: 7 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

use Eventjet\CodingStandard\PhpCsFixer\Config;

return Config::basic();
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 OEH WU

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 32 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
{
"name": "oehwu/meta",
"description": "Package with various small handy classes in OEHWU projects",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Thomas Rieschl",
"email": "thomas.rieschl@oeh-wu.at"
}
],
"type": "library",
"require": {
"php": ">=5.4",
"php": ">=8.1",
"ext-curl": "*"
},
"require-dev": {
"infection/infection": "^0.9",
"maglnet/composer-require-checker": "^1.0",
"phpstan/phpstan": "^0.10",
"phpstan/phpstan-strict-rules": "^0.10",
"phpunit/phpunit": "^7.0"
"eventjet/coding-standard": "^3.12",
"infection/infection": "^0.27.0",
"maglnet/composer-require-checker": "^4.6",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.2",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.10"
},
"autoload": {
"psr-4": {
Expand All @@ -31,19 +30,30 @@
}
},
"config": {
"allow-plugins": {
"infection/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
"scripts": {
"check-deps": "vendor/bin/composer-require-checker",
"infection": "vendor/bin/infection --only-covered --min-covered-msi=45",
"infection-xdebug": "@composer run --timeout=0 infection -- --initial-tests-php-options='-d zend_extension=xdebug.so'",
"phpstan": "vendor/bin/phpstan analyse src/ --level 7",
"phpunit": "vendor/bin/phpunit",
"tests": [
"check": [
"@check-deps",
"@infection",
"@cs-check",
"@psalm",
"@phpstan",
"@phpunit"
]
"@phpunit",
"@infection"
],
"check-deps": "composer-require-checker",
"cs-check": "php-cs-fixer fix --dry-run",
"cs-fix": "php-cs-fixer fix",
"infection": "infection -jmax",
"infection-diff": "infection -jmax --git-diff-lines --min-msi=100 --min-covered-msi=100 --ignore-msi-with-no-mutations",
"infection-xdebug": "infection --initial-tests-php-options='-d zend_extension=xdebug.so'",
"phpstan": "phpstan analyze",
"phpunit": "phpunit",
"psalm": "psalm"
}
}
5 changes: 4 additions & 1 deletion example.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';
?>
<!DOCTYPE html>
Expand All @@ -20,4 +23,4 @@

<?= OEHWU\Meta\Cookie::getSnippet() ?>
</body>
</html>
</html>
7 changes: 5 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
level: max
paths:
- src/
- tests/
15 changes: 9 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="vendor/autoload.php">
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
>
<testsuites>
<testsuite name="OEHWU\StudentId">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<source>
<include>
<directory>src</directory>
</whitelist>
</filter>
</include>
</source>
</phpunit>
21 changes: 21 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<psalm
strictBinaryOperands="true"
errorLevel="1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
>
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
32 changes: 14 additions & 18 deletions src/CheckSSL.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
<?php

declare(strict_types=1);

namespace OEHWU\Meta;

use function header;

/**
* Class CheckSSL
*
* Simple Method to check if the connection to the client is encrypted.
*
* The connection to the backend web server is never encrypted, because the SSL wrapper (Pound) resides
* The connection to the backend web server is never encrypted, because the SSL wrapper resides
* on the reverse proxy and encrypts/decrypts at the OEH WU border.
* Pound adds an HTTP header to allow the backend web server to determine if the connection was made using https://
*
* @package OEHWU\Meta
* The reverse proxy adds an HTTP header to allow the backend web server to determine
* if the connection was made using https://
*/
class CheckSSL
final class CheckSSL
{
/**
* Returns true if the X-SSL-Request HTTP header is present, thus the client accessed the ressource using https://
*
* @return bool
*/
public static function isSSL()
public static function isSSL(): bool
{
if (isset($_SERVER['HTTP_X_SSL_REQUEST'])) {
return true;
}

return false;
}

/**
* Redirects the client to HTTPS, if it's not already on HTTPS
*
* We don't use $_SERVER['SERVER_PORT'] because the backend server is unaware of the SSL status, thus on port 80
*
* @return void
*/
public static function redirect()
public static function redirect(): void
{
if (self::isSSL() === true) {
if (self::isSSL()) {
return;
}
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$host = $_SERVER['HTTP_HOST'] ?? '';
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$redirect = 'https://' . $host . $requestUri;
header('Location: ' . $redirect);

return;
}
}
11 changes: 6 additions & 5 deletions src/Cookie.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

declare(strict_types=1);

namespace OEHWU\Meta;

class Cookie
use function file_get_contents;

final class Cookie
{
/**
* @return string
*/
public static function getSnippet()
public static function getSnippet(): string
{
$templatePath = __DIR__ . '/../templates/cookie/';

Expand Down
Loading
Loading