Skip to content

Commit 473ae1a

Browse files
Feature/no security for operations (#20)
* Added ability to set no security on an operation * Swapped out PHP_CodeSniffer for PHP-CS-Fixer * Ran through new code fixer * Fixed Travis CI tests * Added updated test invocation to README
1 parent 980376e commit 473ae1a

12 files changed

Lines changed: 202 additions & 31 deletions

File tree

.php_cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
8+
$finder = Finder::create()
9+
->in(__DIR__)
10+
->exclude([
11+
'media',
12+
'tests',
13+
'vendor',
14+
]);
15+
16+
$rules = [
17+
'@PSR1' => true,
18+
'@PSR2' => true,
19+
20+
'align_multiline_comment' => true,
21+
'array_indentation' => true,
22+
'array_syntax' => [
23+
'syntax' => 'short',
24+
],
25+
'blank_line_after_opening_tag' => true,
26+
'blank_line_before_statement' => [
27+
'statements' => ['return', 'throw'],
28+
],
29+
'cast_spaces' => [
30+
'space' => 'none',
31+
],
32+
'class_attributes_separation' => [
33+
'elements' => ['method', 'property'],
34+
],
35+
'combine_consecutive_issets' => true,
36+
'combine_consecutive_unsets' => true,
37+
'compact_nullable_typehint' => true,
38+
'concat_space' => [
39+
'spacing' => 'one',
40+
],
41+
'declare_equal_normalize' => true,
42+
'declare_strict_types' => true,
43+
'ereg_to_preg' => true,
44+
'fully_qualified_strict_types' => true,
45+
'function_to_constant' => true,
46+
'function_typehint_space' => true,
47+
'heredoc_indentation' => true,
48+
'heredoc_to_nowdoc' => true,
49+
'list_syntax' => true,
50+
'logical_operators' => true,
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_chaining_indentation' => true,
57+
'modernize_types_casting' => true,
58+
'multiline_comment_opening_closing' => true,
59+
'multiline_whitespace_before_semicolons' => true,
60+
'native_function_casing' => true,
61+
'native_function_type_declaration_casing' => true,
62+
'new_with_braces' => true,
63+
'no_alias_functions' => true,
64+
'no_alternative_syntax' => true,
65+
'no_blank_lines_after_class_opening' => true,
66+
'no_blank_lines_after_phpdoc' => true,
67+
'no_break_comment' => [
68+
'comment_text' => 'No break.',
69+
],
70+
'no_empty_phpdoc' => true,
71+
'no_empty_statement' => true,
72+
'no_extra_blank_lines' => true,
73+
'no_leading_import_slash' => true,
74+
'no_leading_namespace_whitespace' => true,
75+
'no_mixed_echo_print' => true,
76+
'no_multiline_whitespace_around_double_arrow' => true,
77+
'no_php4_constructor' => true,
78+
'no_short_bool_cast' => true,
79+
'no_short_echo_tag' => true,
80+
'no_singleline_whitespace_before_semicolons' => true,
81+
'no_spaces_around_offset' => true,
82+
'no_unused_imports' => true,
83+
'no_whitespace_before_comma_in_array' => true,
84+
'no_whitespace_in_blank_line' => true,
85+
'normalize_index_brace' => true,
86+
'object_operator_without_whitespace' => true,
87+
'ordered_imports' => true,
88+
'phpdoc_add_missing_param_annotation' => true,
89+
'phpdoc_align' => [
90+
'align' => 'left',
91+
],
92+
'phpdoc_annotation_without_dot' => true,
93+
'phpdoc_indent' => true,
94+
'phpdoc_no_empty_return' => true,
95+
'phpdoc_no_package' => true,
96+
'phpdoc_order' => true,
97+
'phpdoc_scalar' => true,
98+
'phpdoc_single_line_var_spacing' => true,
99+
'phpdoc_summary' => true,
100+
'phpdoc_trim' => true,
101+
'phpdoc_trim_consecutive_blank_line_separation' => true,
102+
'phpdoc_types' => true,
103+
'phpdoc_types_order' => [
104+
'null_adjustment' => 'always_last',
105+
'sort_algorithm' => 'none',
106+
],
107+
'phpdoc_var_annotation_correct_order' => true,
108+
'phpdoc_var_without_name' => true,
109+
'random_api_migration' => true,
110+
'return_type_declaration' => true,
111+
'semicolon_after_instruction' => true,
112+
'set_type_to_cast' => true,
113+
'short_scalar_cast' => true,
114+
'simple_to_complex_string_variable' => true,
115+
'simplified_null_return' => true,
116+
'single_blank_line_before_namespace' => true,
117+
'single_line_comment_style' => true,
118+
'single_quote' => true,
119+
'single_trait_insert_per_statement' => true,
120+
'standardize_not_equals' => true,
121+
'ternary_operator_spaces' => true,
122+
'ternary_to_null_coalescing' => true,
123+
'trailing_comma_in_multiline_array' => true,
124+
'trim_array_spaces' => true,
125+
'unary_operator_spaces' => true,
126+
];
127+
128+
return Config::create()
129+
->setRules($rules)
130+
->setFinder($finder);

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ install:
2525

2626
# Run the code style and unit tests.
2727
script:
28-
- vendor/bin/phpcs
29-
- vendor/bin/phpunit
28+
- composer test:style
29+
- composer test:unit

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,24 @@ $schema->toJson();
304304

305305
## Running the tests
306306

307-
To run the test suite you can use the following command:
307+
To run the test suite you can use the following commands:
308308

309309
```bash
310-
# Code style tests.
311-
php vendor/bin/phpcs
310+
# To run both style and unit tests.
311+
composer test
312312

313-
# Unit tests.
314-
php vendor/bin/phpunit
313+
# To run only style tests.
314+
composer test:style
315+
316+
# To run only unit tests.
317+
composer test:unit
318+
```
319+
320+
If you receive any errors from the style tests, you can automatically fix most,
321+
if not all of the issues with the following command:
322+
323+
```bash
324+
composer fix:style
315325
```
316326

317327
## Contributing

composer.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
},
2424
"require-dev": {
2525
"phpunit/phpunit": "^7.3",
26-
"squizlabs/php_codesniffer": "^3.4"
26+
"friendsofphp/php-cs-fixer": "^2.15"
27+
},
28+
"scripts": {
29+
"test": [
30+
"@php vendor/bin/php-cs-fixer fix --config=.php_cs --allow-risky=yes --dry-run --diff --verbose --using-cache=no",
31+
"@php vendor/bin/phpunit"
32+
],
33+
"test:style": "@php vendor/bin/php-cs-fixer fix --config=.php_cs --allow-risky=yes --dry-run --diff --verbose --using-cache=no",
34+
"test:unit": "@php vendor/bin/phpunit",
35+
"fix:style": "@php vendor/bin/php-cs-fixer fix --config=.php_cs --allow-risky=yes --diff --verbose --using-cache=no"
2736
}
2837
}

phpcs.xml

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

src/Objects/BaseObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function toJson(): string
5454
}
5555

5656
/**
57-
* Specify data which should be serialized to JSON
57+
* Specify data which should be serialized to JSON.
5858
*
5959
* @return array
6060
*/
@@ -65,8 +65,8 @@ public function jsonSerialize(): array
6565

6666
/**
6767
* @param string $name
68-
* @return mixed
6968
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\PropertyDoesNotExistException
69+
* @return mixed
7070
*/
7171
public function __get(string $name)
7272
{

src/Objects/Discriminator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function propertyName(?string $propertyName): self
4747

4848
/**
4949
* @param array $mapping
50-
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Discriminator
5150
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
51+
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Discriminator
5252
*/
5353
public function mapping(array $mapping): self
5454
{

src/Objects/OAuthFlow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public function refreshUrl(?string $refreshUrl): self
109109

110110
/**
111111
* @param array|null $scopes
112-
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\OAuthFlow
113112
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
113+
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\OAuthFlow
114114
*/
115115
public function scopes(?array $scopes): self
116116
{

src/Objects/Operation.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Response[]|null $responses
2020
* @property bool|null $deprecated
2121
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\SecurityRequirement[]|null $security
22+
* @property bool|null $noSecurity
2223
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Server[]|null $servers
2324
*/
2425
class Operation extends BaseObject
@@ -87,6 +88,11 @@ class Operation extends BaseObject
8788
*/
8889
protected $security;
8990

91+
/**
92+
* @var bool|null
93+
*/
94+
protected $noSecurity;
95+
9096
/**
9197
* @var \GoldSpecDigital\ObjectOrientedOAS\Objects\Server[]|null
9298
*/
@@ -179,8 +185,8 @@ public function action(?string $action): self
179185

180186
/**
181187
* @param \GoldSpecDigital\ObjectOrientedOAS\Objects\Tag[]|string[] $tags
182-
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Operation
183188
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
189+
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Operation
184190
*/
185191
public function tags(...$tags): self
186192
{
@@ -319,6 +325,20 @@ public function security(SecurityRequirement ...$security): self
319325
$instance = clone $this;
320326

321327
$instance->security = $security ?: null;
328+
$instance->noSecurity = null;
329+
330+
return $instance;
331+
}
332+
333+
/**
334+
* @param bool|null $noSecurity
335+
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Operation
336+
*/
337+
public function noSecurity(?bool $noSecurity = true): self
338+
{
339+
$instance = clone $this;
340+
341+
$instance->noSecurity = $noSecurity;
322342

323343
return $instance;
324344
}
@@ -356,7 +376,7 @@ public function toArray(): array
356376
'requestBody' => $this->requestBody,
357377
'responses' => $responses ?: null,
358378
'deprecated' => $this->deprecated,
359-
'security' => $this->security,
379+
'security' => $this->noSecurity ? [] : $this->security,
360380
'servers' => $this->servers,
361381
]);
362382
}

src/Objects/Schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema|null $additionalProperties
3333
* @property int|null $maxProperties
3434
* @property int|null $minProperties
35-
* @property boolean|null $nullable
35+
* @property bool|null $nullable
3636
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Discriminator|null $discriminator
3737
* @property bool|null $readOnly
3838
* @property bool|null $writeOnly
@@ -177,7 +177,7 @@ class Schema extends BaseObject implements SchemaContract
177177
protected $minProperties;
178178

179179
/**
180-
* @var boolean|null
180+
* @var bool|null
181181
*/
182182
protected $nullable;
183183

@@ -515,8 +515,8 @@ public function multipleOf(?int $multipleOf): self
515515

516516
/**
517517
* @param \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema[]|string[] $required
518-
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema
519518
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
519+
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema
520520
*/
521521
public function required(...$required): self
522522
{

0 commit comments

Comments
 (0)