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

17 GitHub workflows #18

Merged
merged 17 commits into from
Jul 3, 2024
29 changes: 18 additions & 11 deletions .github/workflows/phpcs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@ name: "PHP_Codesniffer"

on:
pull_request:
paths:
- "**.php"
- "phpcs.xml.dist"
- ".github/workflows/phpcs.yaml"
# paths:
# - "**.php"
# - "phpcs.xml.dist"
# - ".github/workflows/phpcs.yaml"
push:
paths:
- "**.php"
- "phpcs.xml.dist"
- ".github/workflows/phpcs.yaml"
# paths:
# - "**.php"
# - "phpcs.xml.dist"
# - ".github/workflows/phpcs.yaml"

jobs:
phpcs:
name: PHP_CodeSniffer
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.2', '8.3']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@master

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
fetch-depth: 0 # important!
php-version: ${{ matrix.php-versions }}

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer update --prefer-dist --no-progress --ignore-platform-req="ext-*" ${{ matrix.composer-prefer }}

- name: Run PHP_CodeSniffer
run: vendor/bin/phpcs
42 changes: 16 additions & 26 deletions .github/workflows/phpunit.yaml
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
name: "PHPUnit tests"
name: "PHPUnit"


on:
pull_request:
paths:
- "**.php"
- "phpunit.xml.dist"
- ".github/workflows/phpunit.yaml"
# paths:
# - "**.php"
# - "phpunit.xml.dist"
# - ".github/workflows/phpunit.yaml"
push:
paths:
- "**.php"
- "phpunit.xml.dist"
- ".github/workflows/phpunit.yaml"
# paths:
# - "**.php"
# - "phpunit.xml.dist"
# - ".github/workflows/phpunit.yaml"

jobs:
unit-tests:
name: Unit Tests
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
php-version:
- "8.2"
php-versions: ['8.2', '8.3']
steps:
- uses: actions/checkout@master
- uses: actions/checkout@master

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

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

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-composer-${{ matrix.composer-prefer }}$-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.composer-prefer }}-

- name: Install dependencies
run: composer update --prefer-dist --no-progress --ignore-platform-req="ext-*" ${{ matrix.composer-prefer }}

Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/psalm.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: "Psalm PHP checks"
name: "Psalm"

on:
pull_request:
paths:
- "**.php"
- "psalm.xml"
- ".psalm/baseline.xml"
- ".github/workflows/psalm.yaml"
# paths:
# - "**.php"
# - "psalm.xml"
# - ".psalm/baseline.xml"
# - ".github/workflows/psalm.yaml"
push:
paths:
- "**.php"
- "psalm.xml"
- ".psalm/baseline.xml"
- ".github/workflows/psalm.yaml"
# paths:
# - "**.php"
# - "psalm.xml"
# - ".psalm/baseline.xml"
# - ".github/workflows/psalm.yaml"

jobs:
psalm:
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
"phpoffice/phpspreadsheet": "^2.1"
},
"require-dev": {
"fig-r/psr2r-sniffer": "^1.3",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^9.5",
"slevomat/coding-standard": "^7.0",
"spryker/code-sniffer": "^0.17.4",
"squizlabs/php_codesniffer": "^3.0",
"vimeo/psalm": "^5.25"
},
Expand All @@ -51,7 +54,10 @@
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"preferred-install": "dist"
"preferred-install": "dist",
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"prefer-stable": true
}
71 changes: 60 additions & 11 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
<?xml version="1.0"?>
<ruleset name="ExcelWriter">
<description>The coding standard of ExcelWriter package</description>
<arg value="p" />
<?xml version="1.0" encoding="UTF-8"?>

<config name="ignore_warnings_on_exit" value="1" />
<config name="ignore_errors_on_exit" value="1" />
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="PHP_CodeSniffer"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Fastbolt coding standard</description>

<arg name="colors" />
<arg value="s" />
<file>src</file>
<file>tests</file>

<!-- Use the PSR2 Standard-->
<rule ref="PSR2" />
</ruleset>
<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>
<arg value="np"/>

<config name="installed_paths"
value="vendor/fig-r/psr2r-sniffer,vendor/slevomat/coding-standard,vendor/spryker/code-sniffer"/>

<!-- Don't hide tokenizer exceptions -->
<rule ref="Internal.Tokenizer.Exception">
<type>error</type>
</rule>

<rule ref="PSR12">
<exclude name="Generic.WhiteSpace.ScopeIndent"/>
<exclude name="Generic.Files.LineEndings"/>
<exclude name="PSR2.Methods.FunctionCallSignature"/>
<exclude name="Squiz.ControlStructures.ControlSignature.NewlineAfterClosingBrace"/>
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
</rule>

<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="true"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>

<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>

<rule ref="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall"/>
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>

<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>

<rule ref="PSR2R.Namespaces.UnusedUseStatement"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>

<rule ref="Spryker.Commenting.FileDocBlock"/>
</ruleset>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
findUnusedBaselineEntry="true"
findUnusedCode="false"
autoloader="vendor/autoload.php"
cacheDirectory="var/cache/psalm/" errorBaseline="./.psalm/baseline.xml">
cacheDirectory="var/cache/psalm/">
<projectFiles>
<directory name="src/"/>

Expand Down
6 changes: 6 additions & 0 deletions src/ColumnFormatter/BaseFormatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter\ColumnFormatter;

use PhpOffice\PhpSpreadsheet\Style\Alignment;
Expand Down
6 changes: 6 additions & 0 deletions src/ColumnFormatter/ColumnFormatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter\ColumnFormatter;

interface ColumnFormatter
Expand Down
6 changes: 6 additions & 0 deletions src/ColumnFormatter/DateFormatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter\ColumnFormatter;

use PhpOffice\PhpSpreadsheet\Style\Alignment;
Expand Down
10 changes: 8 additions & 2 deletions src/ColumnFormatter/FloatFormatter.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter\ColumnFormatter;

use PhpOffice\PhpSpreadsheet\Style\Alignment;
use Fastbolt\ExcelWriter\ColumnSetting;
use PhpOffice\PhpSpreadsheet\Style\Alignment;

class FloatFormatter extends BaseFormatter
{
Expand All @@ -24,7 +30,7 @@ public function getAlignment(): array
*/
public function getNumberFormat(): array
{
$formatCode = '0.'.str_repeat('0', $this->decimalLength);
$formatCode = '0.' . str_repeat('0', $this->decimalLength);

return ['formatCode' => $formatCode];
}
Expand Down
6 changes: 6 additions & 0 deletions src/ColumnFormatter/IntegerFormatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter\ColumnFormatter;

use PhpOffice\PhpSpreadsheet\Style\Alignment;
Expand Down
7 changes: 6 additions & 1 deletion src/ColumnFormatter/StringFormatter.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter\ColumnFormatter;

use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class StringFormatter extends BaseFormatter
{
Expand Down
27 changes: 13 additions & 14 deletions src/ColumnSetting.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* Copyright © Fastbolt Schraubengroßhandels GmbH.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fastbolt\ExcelWriter;

use Fastbolt\ExcelWriter\ColumnFormatter\ColumnFormatter;
Expand All @@ -24,23 +30,23 @@ class ColumnSetting
private ?array $headerStyle;
private ?array $dataStyle;

/** @var callable|string name of the get method (like getId) or a callable taking the object an argument */
/** @var string|callable|null name of the get method (like getId) or a callable taking the object an argument */
private $getter;


/**
* @param string $header column header
* @param string $format format of the values
* @param string|callable $getter method name of the getter of the attribute or a callable
* @param string|callable|null $getter method name of the getter of the attribute or a callable
* @param int $decimalLength only for float columns: how many decimals are displayed
*/
public function __construct(
string $header,
string $format = self::FORMAT_STRING,
$getter = '',
string|callable|null $getter = '',
int $decimalLength = 2,
$headerStyle = null,
$dataStyle = null
?array $headerStyle = null,
?array $dataStyle = null
) {
$this->header = $header;
$this->format = $format;
Expand Down Expand Up @@ -103,19 +109,12 @@ public function setFormat(string $format): ColumnSetting
return $this;
}

/**
* @return string|callable
*/
public function getGetter()
public function getGetter(): string|callable|null
{
return $this->getter;
}

/**
* @param string|callable $getter
* @return $this
*/
public function setGetter($getter): self
public function setGetter(string|callable|null $getter): self
{
$this->getter = $getter;

Expand Down
Loading