Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit b5d64f0

Browse files
authored
Fix code style, configure and enable php-cs-fixer on Travis (#33)
* Add missing void return-type * Add strict-type for argument in HeadersConstraint * Change files header * Apply earlier-return * Uuse single quotes * Add missing params in phpdoc * Use strict assertiosn in tests * Use strict comparisions * Reformsat tests * Reorder class elements * Use multibyte functions * Add php_cs * Add php-cs-fixer to travis jobs * Use multibyte functions * Remove errors allowance of PHP7.3 in Travis
1 parent 17fd9dd commit b5d64f0

20 files changed

+350
-168
lines changed

.php_cs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
/**
3+
* This source file is proprietary and part of Rebilly.
4+
*
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
8+
*
9+
* @see https://www.rebilly.com
10+
*/
11+
12+
$header = <<<'EOF'
13+
This source file is proprietary and part of Rebilly.
14+
15+
(c) Rebilly SRL
16+
Rebilly Ltd.
17+
Rebilly Inc.
18+
19+
@see https://www.rebilly.com
20+
EOF;
21+
22+
$rules = [
23+
'@PSR2' => true,
24+
'align_multiline_comment' => true,
25+
'array_syntax' => ['syntax' => 'short'],
26+
'blank_line_before_statement' => true,
27+
'binary_operator_spaces' => true,
28+
'cast_spaces' => true,
29+
'class_attributes_separation' => true,
30+
'combine_consecutive_issets' => true,
31+
'combine_consecutive_unsets' => true,
32+
'combine_nested_dirname' => true,
33+
'compact_nullable_typehint' => true,
34+
'concat_space' => ['spacing' => 'one'],
35+
'declare_equal_normalize' => true,
36+
// Useful but dangerous fixer. Requires a lot of changes and testing.
37+
// 'declare_strict_types' => true,
38+
'dir_constant' => true,
39+
'header_comment' => [
40+
'header' => $header,
41+
'commentType' => 'PHPDoc',
42+
'separate' => 'bottom',
43+
'location' => 'after_open',
44+
],
45+
// Requires php 7.3+.
46+
// 'heredoc_indentation' => true,
47+
'heredoc_to_nowdoc' => true,
48+
'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'version']],
49+
'is_null' => true,
50+
'list_syntax' => ['syntax' => 'short'],
51+
'lowercase_cast' => true,
52+
'lowercase_static_reference' => true,
53+
'magic_constant_casing' => true,
54+
'magic_method_casing' => true,
55+
'mb_str_functions' => true,
56+
'method_argument_space' => ['ensure_fully_multiline' => true],
57+
'method_chaining_indentation' => true,
58+
'modernize_types_casting' => true,
59+
'native_function_casing' => true,
60+
// We might want this in future.
61+
// 'native_function_invocation' => true,
62+
'new_with_braces' => true,
63+
'no_blank_lines_after_class_opening' => true,
64+
'no_blank_lines_after_phpdoc' => true,
65+
'no_empty_comment' => true,
66+
'no_empty_phpdoc' => true,
67+
'no_empty_statement' => true,
68+
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
69+
'no_homoglyph_names' => true,
70+
'no_leading_import_slash' => true,
71+
'no_leading_namespace_whitespace' => true,
72+
'no_mixed_echo_print' => true,
73+
'no_multiline_whitespace_around_double_arrow' => true,
74+
'no_null_property_initialization' => true,
75+
'no_short_bool_cast' => true,
76+
'no_singleline_whitespace_before_semicolons' => true,
77+
'no_spaces_around_offset' => true,
78+
'no_superfluous_elseif' => true,
79+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
80+
'no_trailing_comma_in_singleline_array' => true,
81+
'no_unneeded_control_parentheses' => true,
82+
'no_unneeded_curly_braces' => true,
83+
'no_unneeded_final_method' => true,
84+
'no_unreachable_default_argument_value' => true,
85+
'no_unset_on_property' => true,
86+
'no_unused_imports' => true,
87+
'no_useless_else' => true,
88+
'no_useless_return' => true,
89+
'no_whitespace_before_comma_in_array' => true,
90+
'no_whitespace_in_blank_line' => true,
91+
'normalize_index_brace' => true,
92+
'ordered_class_elements' => true,
93+
'ordered_imports' => true,
94+
'php_unit_construct' => true,
95+
'php_unit_dedicate_assert' => ['target' => 'newest'],
96+
'php_unit_expectation' => true,
97+
'php_unit_method_casing' => true,
98+
'php_unit_mock' => true,
99+
'php_unit_namespaced' => true,
100+
'php_unit_no_expectation_annotation' => true,
101+
'php_unit_ordered_covers' => true,
102+
'php_unit_set_up_tear_down_visibility' => true,
103+
'php_unit_strict' => true,
104+
'php_unit_test_annotation' => ['style' => 'annotation'],
105+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
106+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
107+
'phpdoc_annotation_without_dot' => true,
108+
'phpdoc_indent' => true,
109+
'phpdoc_no_useless_inheritdoc' => true,
110+
'phpdoc_order' => true,
111+
'phpdoc_scalar' => true,
112+
'phpdoc_separation' => true,
113+
'phpdoc_single_line_var_spacing' => true,
114+
'phpdoc_summary' => true,
115+
'phpdoc_trim' => true,
116+
'phpdoc_trim_consecutive_blank_line_separation' => true,
117+
'phpdoc_types' => true,
118+
'phpdoc_types_order' => true,
119+
'pow_to_exponentiation' => true,
120+
'protected_to_private' => true,
121+
// This does not work well with test cases ATM.
122+
// 'psr4' => true,
123+
'random_api_migration' => true,
124+
'return_type_declaration' => true,
125+
'self_accessor' => true,
126+
'semicolon_after_instruction' => true,
127+
'short_scalar_cast' => true,
128+
'single_line_comment_style' => true,
129+
'single_quote' => true,
130+
'space_after_semicolon' => true,
131+
'standardize_not_equals' => true,
132+
'strict_comparison' => true,
133+
'strict_param' => true,
134+
'ternary_operator_spaces' => true,
135+
'ternary_to_null_coalescing' => true,
136+
'trailing_comma_in_multiline_array' => true,
137+
'trim_array_spaces' => true,
138+
'unary_operator_spaces' => true,
139+
'visibility_required' => ['property', 'method', 'const'],
140+
'void_return' => true,
141+
'whitespace_after_comma_in_array' => true,
142+
'yoda_style' => ['equal' => false, 'identical' => false],
143+
'object_operator_without_whitespace' => true,
144+
];
145+
146+
$includeDirs = [
147+
__DIR__ . '/src',
148+
__DIR__ . '/tests',
149+
];
150+
151+
$excludeDirs = [];
152+
153+
$finder = PhpCsFixer\Finder::create()
154+
->ignoreDotFiles(true)
155+
->exclude($excludeDirs)
156+
->in($includeDirs);
157+
158+
$config = PhpCsFixer\Config::create()
159+
->setRiskyAllowed(true)
160+
->setRules($rules)
161+
->setFinder($finder);
162+
163+
return $config;

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ matrix:
99
- php: 7.2
1010
env:
1111
- EXECUTE_COVERAGE=true
12-
- php: 7.3
13-
allow_failures:
12+
- EXECUTE_CS_CHECK=true
1413
- php: 7.3
1514

1615
notifications:

src/Exception.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI;

src/JsonSchema/Validator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI\JsonSchema;

src/PhpUnit/Asserts.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI\PhpUnit;

src/PhpUnit/ContentTypeConstraint.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI\PhpUnit;
@@ -27,14 +28,14 @@ public function __construct(array $allowedTypes)
2728
$this->allowedTypes = array_map([$this, 'stripParams'], $allowedTypes);
2829
}
2930

30-
protected function matches($other): bool
31+
public function toString(): string
3132
{
32-
return in_array($this->stripParams($other), $this->allowedTypes, true);
33+
return 'is an allowed content-type (' . implode(', ', $this->allowedTypes) . ')';
3334
}
3435

35-
public function toString(): string
36+
protected function matches($other): bool
3637
{
37-
return 'is an allowed content-type (' . implode(', ', $this->allowedTypes) . ')';
38+
return in_array($this->stripParams($other), $this->allowedTypes, true);
3839
}
3940

4041
private static function stripParams(string $type): string

src/PhpUnit/HeadersConstraint.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI\PhpUnit;
@@ -34,6 +35,11 @@ public function __construct(array $expectedHeadersSchemas)
3435
$this->validator = new Validator('undefined');
3536
}
3637

38+
public function toString(): string
39+
{
40+
return 'matches an specified headers schemas';
41+
}
42+
3743
protected function matches($actualHeaders): bool
3844
{
3945
if (!is_array($actualHeaders)) {
@@ -69,11 +75,6 @@ protected function additionalFailureDescription($other): string
6975
return $this->validator->serializeErrors($this->errors);
7076
}
7177

72-
public function toString(): string
73-
{
74-
return 'matches an specified headers schemas';
75-
}
76-
7778
private static function normalizeJsonSchema($schema): stdClass
7879
{
7980
return json_decode(json_encode($schema));

src/PhpUnit/JsonSchemaConstraint.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI\PhpUnit;
@@ -35,6 +36,11 @@ public function __construct(stdClass $schema, string $context = null)
3536
$this->validator = new Validator($this->context);
3637
}
3738

39+
public function toString(): string
40+
{
41+
return "matches defined {$this->context}";
42+
}
43+
3844
protected function matches($other): bool
3945
{
4046
$this->errors = $this->validator->validate($other, $this->schema);
@@ -51,9 +57,4 @@ protected function additionalFailureDescription($other): string
5157
{
5258
return $this->validator->serializeErrors($this->errors);
5359
}
54-
55-
public function toString(): string
56-
{
57-
return "matches defined {$this->context}";
58-
}
5960
}

src/PhpUnit/MethodsAllowedConstraint.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* This file is part of Rebilly.
3+
* This source file is proprietary and part of Rebilly.
44
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
5+
* (c) Rebilly SRL
6+
* Rebilly Ltd.
7+
* Rebilly Inc.
78
*
8-
* @see http://rebilly.com
9+
* @see https://www.rebilly.com
910
*/
1011

1112
namespace Rebilly\OpenAPI\PhpUnit;
@@ -25,6 +26,11 @@ public function __construct(array $allowedMethods)
2526
$this->allowedMethods = array_map('mb_strtoupper', $allowedMethods);
2627
}
2728

29+
public function toString(): string
30+
{
31+
return 'matches an allowed methods (' . implode(', ', $this->allowedMethods) . ')';
32+
}
33+
2834
protected function matches($other): bool
2935
{
3036
if (is_string($other)) {
@@ -33,9 +39,4 @@ protected function matches($other): bool
3339

3440
return empty(array_diff($this->allowedMethods, array_map('mb_strtoupper', $other)));
3541
}
36-
37-
public function toString(): string
38-
{
39-
return 'matches an allowed methods (' . implode(', ', $this->allowedMethods) . ')';
40-
}
4142
}

0 commit comments

Comments
 (0)