Skip to content

Commit

Permalink
feat: add static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-doehring committed Jul 31, 2021
1 parent 81387db commit f4909f3
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
/.github export-ignore
44 changes: 44 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: phpcs

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
php:
- 8.0

steps:
- name: Checkout code
uses: actions/checkout@v2

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

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Install Composer dependencies
run: |
composer install --no-interaction --no-progress --optimize-autoloader --no-scripts
- name: Execute phpcs
run: ./vendor/bin/phpcs
44 changes: 44 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: phpstan

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
php:
- 8.0

steps:
- name: Checkout code
uses: actions/checkout@v2

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

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Install Composer dependencies
run: |
composer install --no-interaction --no-progress --optimize-autoloader --no-scripts
- name: Execute phpstan
run: ./vendor/bin/phpstan analyse
14 changes: 13 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
},
"require-dev": {
"fakerphp/faker": "^1.14",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^0.12.89",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand All @@ -22,5 +24,15 @@
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"scripts": {
"test": [
"phpunit",
"phpstan analyse",
"phpcs --standard=phpcs.xml"
],
"unit": "phpunit",
"stan": "phpstan analyse",
"cs": "phpcs --standard=phpcs.xml"
}
}
15 changes: 15 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>Custom ruleset Based on PSR12</description>
<file>src</file>
<!-- Rule to be referenced (`PSR12`) -->
<rule ref="PSR12" />
<!-- All files must have "\n" line endings -->
<rule ref="Generic.Files.LineEndings" />
<!-- Specify extensions (.php) -->
<arg name="extensions" value="php" />
<!--Color the result output -->
<arg name="colors" /> <!--Display progress (-p)-->
<!--Display violation rules in error information (-s)-->
<arg value="ps" />
</ruleset>
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 8
paths:
- src
3 changes: 2 additions & 1 deletion src/Factories/BrowserFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Dogado\Laravel\CookieManager\Factories;

use Browser;
Expand All @@ -10,4 +11,4 @@ public function createByRequest(Request $request): Browser
{
return new Browser((string) $request->headers->get('User-Agent', ''));
}
}
}
3 changes: 2 additions & 1 deletion src/Factories/BrowserPolicyFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Dogado\Laravel\CookieManager\Factories;

use Dogado\Laravel\CookieManager\Policies\BrowserPolicy;
Expand All @@ -18,4 +19,4 @@ public function createByRequest(Request $request): BrowserPolicy
{
return new BrowserPolicy($this->browserFactory->createByRequest($request));
}
}
}
14 changes: 10 additions & 4 deletions src/Http/Middleware/SecureResponseCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ protected function secureCookies(Response $response, bool $setSecureAttribute):
protected function getSecureDuplicatedCookie(Cookie $cookie, bool $setSecureAttribute): Cookie
{
$sameSite = $cookie->getSameSite();
if ($this->browserPolicy->canHaveAttributeSameSite() && $setSecureAttribute) {
if ($this->browserPolicy && $this->browserPolicy->canHaveAttributeSameSite() && $setSecureAttribute) {
$sameSite = Cookie::SAMESITE_NONE;
}

return new Cookie(
$cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(),
$cookie->getPath(), $cookie->getDomain(), $setSecureAttribute,
$cookie->isHttpOnly(), $cookie->isRaw(), $sameSite
$cookie->getName(),
$cookie->getValue(),
$cookie->getExpiresTime(),
$cookie->getPath(),
$cookie->getDomain(),
$setSecureAttribute,
$cookie->isHttpOnly(),
$cookie->isRaw(),
$sameSite
);
}
}

0 comments on commit f4909f3

Please sign in to comment.