Skip to content

Commit 8f62192

Browse files
authored
Merge pull request #3 from samsonasik/php-8
Add Php 8 support
2 parents 8cdd71c + afbb56f commit 8f62192

File tree

9 files changed

+155
-59
lines changed

9 files changed

+155
-59
lines changed

.github/workflows/ci_build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: "ci build"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "master"
8+
9+
jobs:
10+
build:
11+
name: PHP ${{ matrix.php-versions }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php-versions: ['7.3', '7.4', 8.0']
17+
steps:
18+
- name: Setup PHP Action
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
extensions: intl
22+
php-version: "${{ matrix.php-versions }}"
23+
coverage: xdebug
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
- run: "composer validate"
27+
- name: "Install dependencies"
28+
run: "composer install --prefer-dist"
29+
- name: "CS Check"
30+
run: "composer cs-check"
31+
- name: "Code analyze"
32+
run: "bin/phpstan analyse src/ --level=max -c phpstan.neon"
33+
- name: "Run test suite"
34+
run: "mkdir -p build/logs && bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml"
35+
- name: Upload coverage to Codecov
36+
uses: codecov/codecov-action@v1
37+
with:
38+
token: ${{ secrets.CODECOV_TOKEN }}
39+
file: ./build/logs/clover.xml
40+
flags: tests
41+
name: codecov-umbrella
42+
yml: ./codecov.yml
43+
fail_ci_if_error: true

.travis.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Naming
22
======
33

44
[![Latest Version](https://img.shields.io/github/release/samsonasik/Naming.svg?style=flat-square)](https://github.com/samsonasik/Naming/releases)
5-
[![Build Status](https://travis-ci.org/samsonasik/Naming.svg?branch=master)](https://travis-ci.org/samsonasik/Naming)
6-
[![Coverage Status](https://coveralls.io/repos/github/samsonasik/Naming/badge.svg?branch=master)](https://coveralls.io/github/samsonasik/Naming?branch=master)
5+
![ci build](https://github.com/samsonasik/ForceHttpsModule/workflows/ci%20build/badge.svg)
6+
[![Code Coverage](https://codecov.io/gh/samsonasik/ForceHttpsModule/branch/master/graph/badge.svg)](https://codecov.io/gh/samsonasik/ForceHttpsModule)
77
[![PHPStan](https://img.shields.io/badge/style-level%20max-brightgreen.svg?style=flat-square&label=phpstan)](https://github.com/phpstan/phpstan)
88
[![Downloads](https://img.shields.io/packagist/dt/samsonasik/naming.svg?style=flat-square)](https://packagist.org/packages/samsonasik/naming)
99

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.2",
24+
"php": "^7.3 || ^8.0",
2525
"laminas/laminas-filter": "^2.9",
2626
"laminas/laminas-validator": "^2.12",
2727
"symfony/polyfill-mbstring": "^1.10",
@@ -31,9 +31,10 @@
3131
"kahlan/kahlan": "^4.7.2",
3232
"laminas/laminas-coding-standard": "^2.0",
3333
"php-coveralls/php-coveralls": "^2.1",
34-
"phpstan/phpstan": "^0.11",
35-
"phpstan/phpstan-webmozart-assert": "^0.11.0",
36-
"squizlabs/php_codesniffer": "3.5.3"
34+
"phpstan/phpstan": "^0.12",
35+
"phpstan/phpstan-webmozart-assert": "^0.12.0",
36+
"rector/rector": "^0.11.53",
37+
"squizlabs/php_codesniffer": "^3.5.8"
3738
},
3839
"config": {
3940
"bin-dir": "bin",

rector.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
4+
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
5+
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
6+
use Rector\Core\Configuration\Option;
7+
use Rector\Core\ValueObject\PhpVersion;
8+
use Rector\Php73\Rector\FuncCall\RegexDashEscapeRector;
9+
use Rector\Set\ValueObject\SetList;
10+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
11+
use Rector\TypeDeclaration\Rector\Param\ParamTypeFromStrictTypedPropertyRector;
12+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
13+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
14+
15+
return static function (ContainerConfigurator $containerConfigurator): void {
16+
$containerConfigurator->import(SetList::CODING_STYLE);
17+
$containerConfigurator->import(SetList::PHP_70);
18+
$containerConfigurator->import(SetList::PHP_71);
19+
$containerConfigurator->import(SetList::PHP_72);
20+
$containerConfigurator->import(SetList::PHP_73);
21+
$containerConfigurator->import(SetList::CODE_QUALITY);
22+
$containerConfigurator->import(SetList::TYPE_DECLARATION);
23+
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
24+
25+
$parameters = $containerConfigurator->parameters();
26+
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/spec']);
27+
28+
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
29+
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
30+
31+
$parameters->set(Option::SKIP, [
32+
// requires php 7.4
33+
CallUserFuncArrayToVariadicRector::class,
34+
ReturnTypeFromStrictTypedPropertyRector::class,
35+
TypedPropertyFromStrictConstructorRector::class,
36+
ParamTypeFromStrictTypedPropertyRector::class,
37+
38+
// some that no need escaped, eg: $# escaped to \$#
39+
ConsistentPregDelimiterRector::class,
40+
]);
41+
};

spec/Filter/NamingSpec.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
use Naming\Filter\Naming;
66

7-
describe('Naming', function () {
7+
describe('Naming', function (): void {
88

9-
describe('filter()', function () {
9+
describe('filter()', function (): void {
1010

11-
it('set striptags, trim, and strip double space with ucwords with set lower first, upper after apostrophe and hyphen', function () {
11+
it('set striptags, trim, and strip double space with ucwords with set lower first, upper after apostrophe and hyphen', function (): void {
1212

1313
$maps = [
1414
'<script>Abdul' => 'Abdul',
1515
'Abdul ' => 'Abdul',
1616
'ABduL' => 'Abdul',
1717
'aBDUL m. ikHsan' => 'Abdul M. Ikhsan',
1818
'abdul Malik I' => 'Abdul Malik I',
19-
'D\'lilah' => 'D\'Lilah',
19+
"D'lilah" => "D'Lilah",
2020
'äX' => 'Äx',
2121
'Veli-matti' => 'Veli-Matti',
2222
];

spec/Validator/NamingSpec.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
});
1414

15-
describe('->isValid', function () {
15+
describe('->isValid', function (): void {
1616

17-
it('returns false for incorrect naming', function () {
17+
it('returns false for incorrect naming', function (): void {
1818

1919
$namings = [
2020
// include special character(s)
@@ -35,11 +35,11 @@
3535
// single strlen($value) === 1 condition
3636
'.',
3737
'-',
38-
'\'',
38+
"'",
3939

4040
// consecutive value == -,',.
4141
'--',
42-
'\'\'',
42+
"''",
4343
'...',
4444
'Foo.....',
4545
];
@@ -51,14 +51,14 @@
5151

5252
});
5353

54-
it('returns true for correct naming', function () {
54+
it('returns true for correct naming', function (): void {
5555

5656
$namings = [
5757
'abdul malik ikhsan',
5858
'abdul m. ikhsan',
5959
'abdul',
6060
'M.',
61-
'D\'Lilah',
61+
"D'Lilah",
6262
'Veli-Matti',
6363
'Setälä',
6464
];

src/Filter/Naming.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function filter($value): string
2929

3030
Assert::string($value);
3131

32-
$chars = ['\'', '-'];
33-
array_walk($chars, function ($row) use (&$value) {
32+
$chars = ["'", '-'];
33+
array_walk($chars, function ($row) use (&$value): void {
3434
$position = mb_strpos($value, $row);
3535
if ($position !== false && isset($value[$position + 1])) {
3636
$value[$position + 1] = mb_strtoupper($value[$position + 1]);

src/Validator/Naming.php

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
use Webmozart\Assert\Assert;
99

1010
use function array_filter;
11-
use function array_keys;
11+
use function array_key_exists;
1212
use function current;
13-
use function in_array;
1413
use function mb_strlen;
1514
use function preg_match;
1615
use function strpos;
@@ -19,15 +18,47 @@
1918

2019
class Naming extends AbstractValidator
2120
{
22-
public const SPECIAL_OR_NUMBER = 'SPECIAL_OR_NUMBER';
23-
public const SINGLE_DOT = 'SINGLE_DOT';
24-
public const SINGLE_HYPHEN = 'SINGLE_HYPHEN';
25-
public const SINGLE_APOSTROPHE = 'SINGLE_APOSTROPHE';
26-
public const CONSECUTIVE_DOT = 'CONSECUTIVE_DOT';
27-
public const CONSECUTIVE_HYPHEN = 'CONSECUTIVE_HYPHEN';
21+
/**
22+
* @var string
23+
*/
24+
public const SPECIAL_OR_NUMBER = 'SPECIAL_OR_NUMBER';
25+
26+
/**
27+
* @var string
28+
*/
29+
public const SINGLE_DOT = 'SINGLE_DOT';
30+
31+
/**
32+
* @var string
33+
*/
34+
public const SINGLE_HYPHEN = 'SINGLE_HYPHEN';
35+
36+
/**
37+
* @var string
38+
*/
39+
public const SINGLE_APOSTROPHE = 'SINGLE_APOSTROPHE';
40+
41+
/**
42+
* @var string
43+
*/
44+
public const CONSECUTIVE_DOT = 'CONSECUTIVE_DOT';
45+
46+
/**
47+
* @var string
48+
*/
49+
public const CONSECUTIVE_HYPHEN = 'CONSECUTIVE_HYPHEN';
50+
51+
/**
52+
* @var string
53+
*/
2854
public const CONSECUTIVE_APOSTROPHE = 'CONSECUTIVE_APOSTROPHE';
29-
public const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD';
3055

56+
/**
57+
* @var string
58+
*/
59+
public const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD';
60+
61+
/** @var array<string, string> */
3162
protected $messageTemplates = [
3263
self::SPECIAL_OR_NUMBER => 'Names can contain only letters, hyphens, apostrophe, spaces & full stops',
3364
self::SINGLE_DOT => 'Single "." character is not allowed',
@@ -39,6 +70,9 @@ class Naming extends AbstractValidator
3970
self::DOT_TOBE_IN_LAST_WORD => '"." must be at last word character',
4071
];
4172

73+
/**
74+
* @param mixed[] $options
75+
*/
4276
public function __construct(array $options = [])
4377
{
4478
parent::__construct($options);
@@ -59,27 +93,27 @@ public function isValid($value): bool
5993
$length = mb_strlen($value);
6094
if ($length === 1) {
6195
$messageTemplates = [
62-
'.' => self::SINGLE_DOT,
63-
'-' => self::SINGLE_HYPHEN,
64-
'\'' => self::SINGLE_APOSTROPHE,
96+
'.' => self::SINGLE_DOT,
97+
'-' => self::SINGLE_HYPHEN,
98+
"'" => self::SINGLE_APOSTROPHE,
6599
];
66100

67-
if (in_array($value, array_keys($messageTemplates), true)) {
101+
if (array_key_exists($value, $messageTemplates)) {
68102
$this->error($messageTemplates[$value]);
69103
return false;
70104
}
71105
} else {
72106
$messageTemplates = [
73-
'..' => self::CONSECUTIVE_DOT,
74-
'--' => self::CONSECUTIVE_HYPHEN,
75-
'\'\'' => self::CONSECUTIVE_APOSTROPHE,
107+
'..' => self::CONSECUTIVE_DOT,
108+
'--' => self::CONSECUTIVE_HYPHEN,
109+
"''" => self::CONSECUTIVE_APOSTROPHE,
76110
];
77111

78-
$error = array_filter($messageTemplates, function ($key) use ($value) {
112+
$error = array_filter($messageTemplates, function ($key) use ($value): bool {
79113
return strpos($value, $key) !== false;
80114
}, ARRAY_FILTER_USE_KEY);
81115

82-
if ($error) {
116+
if ($error !== []) {
83117
$this->error(current($error));
84118
return false;
85119
}

0 commit comments

Comments
 (0)