Skip to content

Commit

Permalink
Update to Symfony 5.4 (#63)
Browse files Browse the repository at this point in the history
* Now supporting Symfony 5.4
* Added 100% line coverage in unit tests.
* Added Codecov instead of Coveralls
* Rector and Stan fixes for Symfony 5.4
  • Loading branch information
BowlOfSoup authored Nov 7, 2023
1 parent 6f2128a commit f22e325
Show file tree
Hide file tree
Showing 57 changed files with 483 additions and 272 deletions.
3 changes: 0 additions & 3 deletions .coveralls.yml

This file was deleted.

19 changes: 11 additions & 8 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ private function pipedExec(string $command, array &$output = null, int &$returnV
}
}

/* Based on dev-master|^2.0 of php-cs-fixer */
return Config::create()
return (new Config())
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules([
Expand All @@ -233,17 +232,21 @@ private function pipedExec(string $command, array &$output = null, int &$returnV
'no_blank_lines_before_namespace' => false,
'ordered_imports' => true,
'phpdoc_align' => false,
'phpdoc_inline_tag' => false,
'general_phpdoc_tag_rename' => false,
'phpdoc_order' => true,
'simplified_null_return' => false,
'binary_operator_spaces' => [
'align_double_arrow' => false,
'align_equals' => false
],
'no_unused_imports' => true,
'declare_strict_types' => true,
'final_internal_class' => false,
'general_phpdoc_annotation_remove' => ['author', 'copyright', 'category', 'version'],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author',
'copyright',
'category',
'version',
],
'case_sensitive' => false,
],
'global_namespace_import' => ['import_classes' => null],
'list_syntax' => ['syntax' => 'short'],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], // according to the documentation this is the default, but it ain't
Expand Down
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ cache:

jobs:
include:
- php: 7.2
env: SYMFONY_VERSION=~5.4
- php: 7.4
env: SYMFONY_VERSION=~4.4
- php: 7.4
env: SYMFONY_VERSION=~5.1
env: SYMFONY_VERSION=~5.4
- dist: "jammy"
php: 8.2
env: SYMFONY_VERSION=~5.1
env: SYMFONY_VERSION=~5.4
fast_finish: true

before_install:
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --version=1.10.22
- php -r "unlink('composer-setup.php');"
- sudo mv composer.phar /usr/local/bin/composer
- curl -Os https://uploader.codecov.io/latest/linux/codecov
- chmod +x codecov

install:
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
Expand All @@ -30,7 +32,5 @@ install:
script:
- vendor/bin/rector process --dry-run --no-progress-bar --ansi
- vendor/bin/phpstan analyze --no-progress --ansi
- php vendor/bin/phpunit

after_script:
- php vendor/bin/coveralls -v
- XDEBUG_MODE=coverage php vendor/bin/phpunit
- ./codecov
File renamed without changes.
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ Bowl Of Soup Normalizer
=====

[![Build Status](https://travis-ci.org/BowlOfSoup/NormalizerBundle.svg?branch=master)](https://travis-ci.org/BowlOfSoup/NormalizerBundle)
[![Coverage Status](https://coveralls.io/repos/github/BowlOfSoup/NormalizerBundle/badge.svg?branch=master)](https://coveralls.io/github/BowlOfSoup/NormalizerBundle?branch=master)
[![codecov](https://codecov.io/gh/BowlOfSoup/NormalizerBundle/branch/master/graph/badge.svg?token=2OW4EWvMUD)](https://codecov.io/gh/BowlOfSoup/NormalizerBundle)
[![PHP Version](https://img.shields.io/badge/php-7.2.x%20--%208.2.x-blue.svg)](https://www.php.net/)
[![Symfony Version](https://img.shields.io/badge/symfony-4.4.x%20--%205.1.x-blue.svg)](https://symfony.com/)

[![Symfony Version](https://img.shields.io/badge/symfony-5.4.x-blue.svg)](https://symfony.com/)

Installation
-----
Expand Down Expand Up @@ -52,3 +51,39 @@ Why use this normalizer and not ...
- It's designed with speed in mind. Not packed with features for which you don't use half of it
- It has proven itself in a complex application with 15.000+ daily end users

Development
-----
The following CI tools can be used to check for code quality before pushing code:

### Rector
Rector can be used to automated code upgrades and refactoring. Try a dry-run first!
```bash
vendor/bin/rector process --dry-run --no-progress-bar --ansi
```

### PHPStan
PHPStan is a static code analysis tool that focuses on finding errors in the code.
Fixing the outcome of PHPStan prevents possible bugs and errors.
```bash
vendor/bin/phpstan
```

### PHPUnit
Speaks for itself, code should be tested. Run with coverage (output = tests/coverage):
```bash
XDEBUG_MODE=coverage php -dzend_extension=xdebug.so vendor/bin/phpunit
```
Or without coverage:
```bash
vendor/bin/phpunit
```

**Code coverage** `master`:

<img src="https://codecov.io/gh/BowlOfSoup/NormalizerBundle/branch/master/graphs/sunburst.svg?token=2OW4EWvMUD" width="200">

### Code style fixer
Have php-cs-fixer automatically fix styling.
```bash
vendor/bin/php-cs-fixer fix
```
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
"ext-simplexml": "*",
"ext-libxml": "*",
"ext-dom": "*",
"doctrine/annotations": "1.*",
"doctrine/annotations": "~1.13.0",
"doctrine/cache": "~1.0",
"php": ">=7.2",
"symfony/framework-bundle": "~4.4|~5.0",
"symfony/translation": "~4.4|~5.0"
"symfony/framework-bundle": "~5.4",
"symfony/translation": "~5.4"
},
"require-dev": {
"doctrine/common": "~2.12",
"doctrine/common": "~3.0",
"doctrine/collections": "1.*",
"php-coveralls/php-coveralls": "^2.0",
"phpunit/phpunit": "^8.5",
"friendsofphp/php-cs-fixer": "^2.10",
"phpunit/phpunit": "^8.0",
"friendsofphp/php-cs-fixer": "^3.0",
"rector/rector": "^0.18.6",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-symfony": "^1.3"
},
"autoload": {
Expand All @@ -48,7 +46,7 @@
},
"symfony": {
"allow-contrib": false,
"require": "4.4.* || 5.1.*"
"require": "5.4.*"
}
}
}
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
parameters:
level: 1
level: 3
paths:
- 'src/'
- 'tests/'

tmpDir: var/cache/phpstan

includes:
- vendor/phpstan/phpstan-mockery/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
50 changes: 25 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="full">
<directory>tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="full">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<file>BowlOfSoupNormalizerBundle.php</file>
<directory>src/DependencyInjection</directory>
<directory>src/EventListener</directory>
<directory>src/Exception</directory>
<directory>src/Model</directory>
<directory>src/Resources</directory>
<directory>tests</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<file>src/BowlOfSoupNormalizerBundle.php</file>
<directory>src/DependencyInjection</directory>
<directory>src/EventListener</directory>
<directory>src/Exception</directory>
<directory>src/Model</directory>
<directory>src/Resources</directory>
<directory>tests</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="tests/coverage/clover.xml"/>
<log type="coverage-html" target="tests/coverage" />
</logging>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="tests/coverage/clover.xml"/>
<log type="coverage-html" target="tests/coverage" />
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_72,
SymfonyLevelSetList::UP_TO_SYMFONY_51,
SymfonyLevelSetList::UP_TO_SYMFONY_54,
]);

$rectorConfig->importNames(true, false);
Expand Down
10 changes: 6 additions & 4 deletions src/Annotation/AbstractAnnotation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace BowlOfSoup\NormalizerBundle\Annotation;

abstract class AbstractAnnotation
Expand Down Expand Up @@ -36,14 +38,14 @@ protected function validateProperties($property, string $propertyName, array $pr
throw new \InvalidArgumentException(sprintf(static::EXCEPTION_EMPTY, $propertyName, $annotation));
}

if (isset($propertyOptions['type']) &&
!$this->hasCorrectType($propertyOptions['type'], $property)
if (isset($propertyOptions['type'])
&& !$this->hasCorrectType($propertyOptions['type'], $property)
) {
throw new \InvalidArgumentException(sprintf(static::EXCEPTION_TYPE, $propertyName, $annotation));
}

if (isset($propertyOptions['assert']) &&
!$this->hasValidAssertion($propertyOptions['assert'], $property)
if (isset($propertyOptions['assert'])
&& !$this->hasValidAssertion($propertyOptions['assert'], $property)
) {
throw new \InvalidArgumentException(sprintf(static::EXCEPTION_TYPE_SUPPORTED, $property, $annotation));
}
Expand Down
25 changes: 14 additions & 11 deletions src/Annotation/Normalize.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

namespace BowlOfSoup\NormalizerBundle\Annotation;

/**
* Register normalization properties.
*
* @Annotation
*
* @Target({"CLASS","PROPERTY","METHOD"})
*/
class Normalize extends AbstractAnnotation
Expand All @@ -22,26 +25,26 @@ class Normalize extends AbstractAnnotation
'maxDepth' => ['type' => 'integer'],
];

/** @var string */
private $name;
/** @var string|null */
private $name = null;

/** @var string */
private $format;
/** @var string|null */
private $format = null;

/** @var string */
private $callback;
/** @var string|null */
private $callback = null;

/** @var bool */
private $normalizeCallbackResult = false;

/** @var bool */
private $skipEmpty = false;

/** @var int */
private $maxDepth;
/** @var int|null */
private $maxDepth = null;

/** @var string */
protected $type;
/** @var string|null */
protected $type = null;

public function __construct(array $properties)
{
Expand Down Expand Up @@ -95,7 +98,7 @@ public function getMaxDepth(): ?int
return $this->maxDepth;
}

public function getType(): string
public function getType(): ?string
{
return $this->type;
}
Expand Down
11 changes: 7 additions & 4 deletions src/Annotation/Serialize.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<?php

declare(strict_types=1);

namespace BowlOfSoup\NormalizerBundle\Annotation;

/**
* Register serialization, encoding properties.
*
* @Annotation
*
* @Target({"CLASS"})
*/
class Serialize extends AbstractAnnotation
{
/** @var array */
/** @var array|array[] */
private $supportedProperties = [
'group' => ['type' => 'array'],
'wrapElement' => ['type' => 'string'],
'sortProperties' => ['type' => 'boolean']
'sortProperties' => ['type' => 'boolean'],
];

/** @var string */
private $wrapElement;
/** @var string|null */
private $wrapElement = null;

/** @var bool */
private $sortProperties = false;
Expand Down
9 changes: 5 additions & 4 deletions src/Annotation/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@

/**
* @Annotation
*
* @Target({"PROPERTY","METHOD"})
*/
class Translate extends AbstractAnnotation
{
/** @var array */
/** @var array|array[] */
private $supportedProperties = [
'group' => ['type' => 'array'],
'domain' => ['type' => 'string'],
'locale' => ['type' => 'string'],
];

/** @var string|null */
private $domain;
private $domain = null;

/** @var string|null */
private $locale;
/** @var null */
private $locale = null;

public function __construct(array $properties)
{
Expand Down
Loading

0 comments on commit f22e325

Please sign in to comment.