Skip to content

Commit

Permalink
Merge pull request #2 from enflow/laravel10
Browse files Browse the repository at this point in the history
  • Loading branch information
mbardelmeijer authored Feb 24, 2023
2 parents ed7115f + 2196077 commit 667498c
Show file tree
Hide file tree
Showing 35 changed files with 178 additions and 184 deletions.
19 changes: 14 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/example export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore

# All test snapshots and text stubs must have LF line endings
tests/**/__snapshots__/** text eol=lf
tests/**/stubs/** text eol=lf
tests/**/stubs/**/*.jpg binary
tests/**/stubs/**/*.png binary
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
32 changes: 32 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: dependabot-auto-merge
on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:

- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: Check & fix styling
name: Fix PHP code style issues

on: [push]
on:
push:
paths:
- '**.php'

jobs:
php-cs-fixer:
php-code-styling:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
67 changes: 36 additions & 31 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: run-tests

on: [push, pull_request]
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
Expand All @@ -9,37 +13,38 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1]
laravel: [9.*, 8.*]
dependency-version: [prefer-lowest, prefer-stable]
php: [8.2]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: ^6.23
- laravel: 10.*
testbench: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

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

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/phpunit
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.cache
composer.lock
coverage
docs
phpunit.xml
psalm.xml
vendor
42 changes: 0 additions & 42 deletions .php-cs-fixer.dist.php

This file was deleted.

14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
}
],
"require": {
"php": "^8.1",
"illuminate/support": "^8.75|^9.0"
"php": "^8.2",
"illuminate/support": "^10.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.2",
"orchestra/testbench": "^6.23|^7.0",
"phpunit/phpunit": "^9.5",
"spatie/phpunit-snapshot-assertions": "^4.2"
"laravel/pint": "^1.0",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^10.0",
"spatie/phpunit-snapshot-assertions": "^5.0"
},
"config": {
"sort-packages": true
Expand All @@ -42,7 +42,7 @@
}
},
"scripts": {
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"format": "vendor/bin/pint",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/spritesheet.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;" id="svg-spritesheet">
<svg xmlns="http://www.w3.org/2000/svg" id="svg-spritesheet" @if (config('svg.inline_style', true))style="display: none;"@else class="{{ config('svg.hidden_class', 'hidden') }}" hidden @endif>
@foreach ($spritesheet as $svg)
<symbol id="{{ $svg->id() }}" viewBox="{{ implode(' ', $svg->viewBox()) }}">
{!! $svg->inner() !!}
Expand Down
4 changes: 2 additions & 2 deletions src/DomParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class DomParser
{
public static function node(Svg $svg): DOMNode
{
return StaticCache::once(static::class . '@node-' . $svg->id(), function () use ($svg) {
return StaticCache::once(static::class.'@node-'.$svg->id(), function () use ($svg) {
$contentsWithoutComments = preg_replace('/<!--(.|\s)*?-->/', '', $svg->contents);

$dom = new DOMDocument();
@$dom->loadXML($contentsWithoutComments);

return $dom->getElementsByTagName("svg")->item(0);
return $dom->getElementsByTagName('svg')->item(0);
});
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/PackNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class PackNotFoundException extends Exception implements SvgException
{
public static function create(string $name)
public static function create(string $name): self
{
$packs = app(PackCollection::class)->keys()->join(', ', ' and ');

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/SvgInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SvgInvalidException extends Exception implements SvgException
{
public static function viewportInvalid(Svg $svg, string $viewPort)
public static function viewportInvalid(Svg $svg, string $viewPort): self
{
$viewPort = empty($viewPort) ? 'empty' : $viewPort;

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/SvgMustBeRendered.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SvgMustBeRendered extends Exception implements SvgException
{
public static function create(Svg $svg)
public static function create(Svg $svg): self
{
return new static("Svg '{$svg->name}' must be rendered before using this method.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/SvgNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SvgNotFoundException extends Exception implements SvgException
{
public static function create(string $name)
public static function create(string $name): self
{
return new static("SVG '{$name}' could not be found.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/InnerParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class InnerParser
{
public static function parse(Svg $svg)
{
return StaticCache::once(static::class . '@parse-' . $svg->id(), function () use ($svg) {
return StaticCache::once(static::class.'@parse-'.$svg->id(), function () use ($svg) {
return array_reduce(
iterator_to_array(DomParser::node($svg)->childNodes),
function ($carry, DOMNode $child) {
Expand All @@ -18,7 +18,7 @@ function ($carry, DOMNode $child) {
$child->setAttribute('fill', 'currentColor');
}

return $carry . $child->ownerDocument->saveHTML($child);
return $carry.$child->ownerDocument->saveHTML($child);
}
);
});
Expand Down
12 changes: 5 additions & 7 deletions src/Middleware/InjectSvgSpritesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
use Enflow\Svg\Spritesheet;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\Response as SymfonyBaseResponse;

class InjectSvgSpritesheet
{
private Spritesheet $spritesheet;

public function __construct(Spritesheet $spritesheet)
public function __construct(private Spritesheet $spritesheet)
{
$this->spritesheet = $spritesheet;
}

public function handle(Request $request, Closure $next)
Expand Down Expand Up @@ -49,7 +47,7 @@ private function injectStylesheet(SymfonyBaseResponse $response): SymfonyBaseRes
{
if (Str::contains($content = $response->getContent(), '<head>') && ! Str::contains($content, 'svg-stylesheet')) {
// We insert it in the top part of the <head> as then custom CSS will overrule ours
$response->setContent(str_replace('<head>', '<head>' . $this->stylesheet(), $content));
$response->setContent(str_replace('<head>', '<head>'.$this->stylesheet(), $content));
}

return $response;
Expand All @@ -63,14 +61,14 @@ private function injectSpritesheet(SymfonyBaseResponse $response): SymfonyBaseRe

if (! empty($matches[0]) && ! empty($matches[1]) && ! empty($matches[2])) {
// We insert it in the top part of the <body> as then the CSS can load first before the SVG body is sent.
$response->setContent($matches[0] . $matches[1] . $this->spritesheet->toHtml() . $matches[2]);
$response->setContent($matches[0].$matches[1].$this->spritesheet->toHtml().$matches[2]);
}
}

return $response;
}

private function stylesheet()
private function stylesheet(): HtmlString
{
return $this->spritesheet->toStylesheet();
}
Expand Down
Loading

0 comments on commit 667498c

Please sign in to comment.