Skip to content

Commit

Permalink
upgrade for next release
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Kusmitsch committed Sep 24, 2024
1 parent 3e703a5 commit b45712c
Show file tree
Hide file tree
Showing 58 changed files with 435 additions and 1,229 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [6.0.0]

Changed
- [BC Break] Doctrine Annotations are no longer used in this project. Annotations have been replaced by PHP attributes. If your codebase or any third-party dependencies still rely on annotations, please migrate to attributes or adjust accordingly.
- [BC Break] The project now requires PHP 8.2 or higher. Ensure that your development and production environments are updated to PHP 8.2+.
- [BC Break] The project now requires PHPUnit version 11 or higher. Ensure that your environment is compatible with PHPUnit 11+ before running tests.
- [BC Break] All classes previously marked with @deprecated and replaced by {@link Laminas} have been removed. If your code still relies on these deprecated classes, please update your references to use the corresponding Laminas classes.

- Add squizlabs/php_codesniffer library.
- Add require-dev ext-pcov for PHPUnit Code Coverage
- PHPCS Coding Standard: The project now exclusively uses PSR-12 as the coding standard. This change ensures that the code adheres to the PSR-12 guidelines, promoting consistency and readability.
- Updated the laminas/laminas-filter bundle from version ^2.9 to ^2.37
- Remove the laminas/laminas-zendframework-bridge bundle.
- Remove the dms/coding-standard bundle.


From v3.0.0 onwards this file will always be updated with notable changes and BC breaks.
This project follows semver.

Expand Down
90 changes: 6 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,6 @@ Use composer to add DMS\Filter to your app

## Usage

### Annotation way

Your Entity:

```php
<?php

namespace App\Entity;

//Import Annotations
use DMS\Filter\Rules as Filter;

class User
{

/**
* @Filter\StripTags()
* @Filter\Trim()
* @Filter\StripNewlines()
*
* @var string
*/
public string $name;

/**
* @Filter\StripTags()
* @Filter\Trim()
* @Filter\StripNewlines()
*
* @var string
*/
public string $email;

}
?>
```

Filtering:

```php
<?php
//Get Doctrine Reader
$reader = new Annotations\AnnotationReader();
$reader->setEnableParsePhpImports(true);

//Load AnnotationLoader
$loader = new Mapping\Loader\AnnotationLoader($reader);
$this->loader = $loader;

//Get a MetadataFactory
$metadataFactory = new Mapping\ClassMetadataFactory($loader);

//Get a Filter
$filter = new DMS\Filter\Filter($metadataFactory);


//Get your Entity
$user = new App\Entity\User();
$user->name = "My <b>name</b>";
$user->email = " [email protected]";

//Filter you entity
$filter->filter($user);

echo $user->name; //"My name"
echo $user->email; //"[email protected]"
?>
```

Full example: https://gist.github.com/1098352

### Attribute way

Your Entity:

```php
Expand Down Expand Up @@ -115,13 +42,15 @@ Filtering:
<?php
//Load AttributeLoader
$loader = new Mapping\Loader\AttributeLoader();
$this->loader = $loader;

//Get a MetadataFactory
$metadataFactory = new Mapping\ClassMetadataFactory($loader);

//Get a FilterLoader
$filterLoader = new \DMS\Filter\Filters\Loader\FilterLoader();

//Get a Filter
$filter = new DMS\Filter\Filter($metadataFactory);
$filter = new DMS\Filter\Filter($metadataFactory, $filterLoader);


//Get your Entity
Expand All @@ -130,19 +59,12 @@ Filtering:
$user->email = " [email protected]";

//Filter you entity
$filter->filter($user);
$filter->filterEntity($user);

echo $user->name; //"My name"
echo $user->email; //"[email protected]"
?>
```

## Dependencies

This package relies on these external libraries:

* Doctrine Annotations

## Contributing

Feel free to send pull requests, just follow these guides:
Expand All @@ -157,4 +79,4 @@ Feel free to send pull requests, just follow these guides:

This library is inspired by the Symfony 2 Validator component and is meant to work alongside it.

Symfony 2 Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator
Symfony Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
],

"require": {
"php": "~8.0 || ~8.1",
"doctrine/annotations": "^1.13",
"laminas/laminas-zendframework-bridge": "^1.0"
"php": "^8.2"
},

"require-dev": {
"doctrine/cache": "~1.3",
"phpunit/phpunit": "^9",
"laminas/laminas-filter": "^2.9",
"dms/coding-standard": "^12"
"ext-pcov": "*",
"laminas/laminas-filter": "^2.37",
"phpunit/phpunit": "^11",
"squizlabs/php_codesniffer": "3.*",
"symfony/cache": "^6.4 | ^7.0"
},
"autoload": {
"psr-0": {
Expand Down
19 changes: 4 additions & 15 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
<?xml version="1.0"?>
<ruleset name="PHPCS Coding Standards for DMS">

<arg name="basepath" value="."/>
<arg name="extensions" value="php"/> <!-- which extensions to look for -->
<arg name="parallel" value="80"/> <!-- how many parallel processes to run -->
<arg name="colors"/>
<arg name="cache" value=".phpcs.cache"/> <!-- cache the results and don't commit them -->
<arg value="nps"/> <!-- n = ignore warnings, p = show progress -->
<rule ref="PSR12"/>

<file>src</file>
<file>tests</file>

<rule ref="DMS">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop"/>
</rule>
</ruleset>


<exclude-pattern>vendor/*</exclude-pattern>
</ruleset>
62 changes: 42 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" beStrictAboutChangesToGlobalState="true">
<coverage>
<include>
<directory suffix=".php">src/DMS</directory>
</include>
<report>
<html outputDirectory="tests/_reports/coverage/" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="DMS Filter Suite">
<directory>tests/DMS</directory>
</testsuite>
</testsuites>
<logging>
<testdoxText outputFile="tests/_reports/testdox/tests.txt"/>
<testdoxHtml outputFile="tests/_reports/testdox/tests.html"/>
</logging>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
executionOrder="depends,defects"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true"
requireCoverageMetadata="false"
shortenArraysForExportThreshold="10">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>

<logging>
<testdoxHtml outputFile="tests/_reports/testdox.html"/>
</logging>
<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<html outputDirectory="tests/_reports/html-coverage" lowUpperBound="50" highLowerBound="90"/>
</report>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion src/DMS/Filter/Filters/BooleanScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BooleanScalar extends BaseFilter
/**
* {@inheritDoc}
*/
public function apply(Rule $rule, $value): mixed
public function apply(Rule $rule, $value): bool
{
return (bool) $value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DMS/Filter/Filters/FloatScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FloatScalar extends BaseFilter
/**
* {@inheritDoc}
*/
public function apply(Rule $rule, $value): mixed
public function apply(Rule $rule, $value): ?float
{
if (is_array($value) || is_object($value)) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/DMS/Filter/Filters/IntScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IntScalar extends BaseFilter
/**
* {@inheritDoc}
*/
public function apply(Rule $rule, $value): mixed
public function apply(Rule $rule, $value): int
{
return (int) ($value);
}
Expand Down
5 changes: 2 additions & 3 deletions src/DMS/Filter/Filters/RegExp.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RegExp extends BaseFilter
public function apply(Rule $rule, $value): mixed
{
//Build pattern
$pattern = $this->checkUnicodeSupport() && $rule->unicodePattern !== null
$pattern = $this->checkUnicodeSupport()
? $rule->unicodePattern
: $rule->pattern;

Expand All @@ -43,8 +43,7 @@ public function apply(Rule $rule, $value): mixed
public function checkUnicodeSupport(): bool
{
if (! isset(static::$unicodeEnabled)) {
//phpcs:disable SlevomatCodingStandard.ControlStructures.UselessTernaryOperator.UselessTernaryOperator
static::$unicodeEnabled = @preg_match('/\pL/u', 'a') ? true : false;
static::$unicodeEnabled = (bool)(@preg_match('/\pL/u', 'a'));
}

return static::$unicodeEnabled;
Expand Down
2 changes: 1 addition & 1 deletion src/DMS/Filter/Filters/ToLower.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ToLower extends BaseFilter
*
* @param \DMS\Filter\Rules\ToLower $rule
*/
public function apply(Rule $rule, $value): mixed
public function apply(Rule $rule, $value): string
{
if ($this->useEncoding($rule)) {
return mb_strtolower((string) $value, $rule->encoding);
Expand Down
5 changes: 2 additions & 3 deletions src/DMS/Filter/Filters/ToUpper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ToUpper extends BaseFilter
*
* @param \DMS\Filter\Rules\ToUpper $rule
*/
public function apply(Rule $rule, $value): mixed
public function apply(Rule $rule, $value): string
{
if ($this->useEncoding($rule)) {
return mb_strtoupper((string) $value, $rule->encoding);
Expand All @@ -52,8 +52,7 @@ public function useEncoding(\DMS\Filter\Rules\ToUpper $rule): bool
);
}

$this->encoding = (string) $rule->encoding;
$encodings = array_map('strtolower', mb_list_encodings());
$encodings = array_map('strtolower', mb_list_encodings());

if (! in_array(strtolower($rule->encoding), $encodings)) {
throw new FilterException(
Expand Down
Loading

0 comments on commit b45712c

Please sign in to comment.