Skip to content

Commit 79c47da

Browse files
committed
Add code style preferences
1 parent e95f0d5 commit 79c47da

File tree

5 files changed

+128
-18
lines changed

5 files changed

+128
-18
lines changed

.php_cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
$finder = Symfony\CS\Finder::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests');
6+
7+
return Symfony\CS\Config::create()
8+
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
9+
->fixers([
10+
// Symfony level fixers
11+
'array_element_no_space_before_comma',
12+
'array_element_white_space_after_comma',
13+
'blankline_after_open_tag',
14+
// 'concat_without_spaces',
15+
'declare_equal_normalize',
16+
'double_arrow_multiline_whitespaces',
17+
'duplicate_semicolon',
18+
'extra_empty_lines',
19+
'function_typehint_space',
20+
'hash_to_slash_comment',
21+
'heredoc_to_nowdoc',
22+
'include',
23+
'join_function',
24+
'list_commas',
25+
'lowercase_cast',
26+
'method_argument_default_value',
27+
'multiline_array_trailing_comma',
28+
'namespace_no_leading_whitespace',
29+
'native_function_casing',
30+
'new_with_braces',
31+
'no_blank_lines_after_class_opening',
32+
'no_empty_comment',
33+
'no_empty_lines_after_phpdocs',
34+
'no_empty_phpdoc',
35+
'no_empty_statement',
36+
'object_operator',
37+
'operators_spaces',
38+
'php_unit_fqcn_annotation',
39+
'phpdoc_annotation_without_dot',
40+
'phpdoc_indent',
41+
'phpdoc_inline_tag',
42+
'phpdoc_no_access',
43+
// 'phpdoc_no_empty_return',
44+
'phpdoc_no_package',
45+
// 'phpdoc_params',
46+
'phpdoc_scalar',
47+
// 'phpdoc_separation',
48+
'phpdoc_short_description',
49+
'phpdoc_single_line_var_spacing',
50+
'phpdoc_to_comment',
51+
'phpdoc_trim',
52+
'phpdoc_type_to_var',
53+
'phpdoc_types',
54+
'phpdoc_var_without_name',
55+
// 'pre_increment',
56+
'print_to_echo',
57+
'remove_leading_slash_use',
58+
'remove_lines_between_uses',
59+
// 'return',
60+
'self_accessor',
61+
'short_bool_cast',
62+
'short_scalar_cast',
63+
'single_array_no_trailing_comma',
64+
'single_blank_line_before_namespace',
65+
'single_quote',
66+
'spaces_after_semicolon',
67+
'spaces_before_semicolon',
68+
'spaces_cast',
69+
'standardize_not_equal',
70+
'ternary_spaces',
71+
'trim_array_spaces',
72+
// 'unalign_double_arrow',
73+
'unalign_equals',
74+
// 'unary_operators_spaces',
75+
'unneeded_control_parentheses',
76+
'unused_use',
77+
'whitespacy_lines',
78+
79+
// Contrib level fixers
80+
// 'align_double_arrow',
81+
// 'align_equals',
82+
// 'class_keyword_remove',
83+
'combine_consecutive_unsets',
84+
'concat_with_spaces',
85+
// 'echo_to_print',
86+
// 'empty_return',
87+
'ereg_to_preg',
88+
// 'header_comment',
89+
// 'logical_not_operators_with_spaces',
90+
// 'logical_not_operators_with_successor_space',
91+
// 'long_array_syntax',
92+
// 'mb_str_functions',
93+
'multiline_spaces_before_semicolon',
94+
// 'newline_after_open_tag',
95+
// 'no_blank_lines_before_namespace',
96+
'no_useless_else',
97+
'no_useless_return',
98+
'ordered_use',
99+
'php4_constructor',
100+
'php_unit_construct',
101+
'php_unit_dedicate_assert',
102+
'php_unit_strict',
103+
// 'phpdoc_order',
104+
// 'phpdoc_var_to_type',
105+
// 'protected_to_private',
106+
'short_array_syntax',
107+
'short_echo_tag',
108+
// 'silenced_deprecation_error',
109+
'strict',
110+
'strict_param',
111+
])
112+
->finder($finder);

src/EncodingException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
*/
1212
class EncodingException extends \Exception
1313
{
14-
1514
}

src/JsonStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct($value, $options = 0)
2828
private function getEncoder()
2929
{
3030
if (!$this->encoder instanceof BufferJsonEncoder) {
31-
throw new RuntimeException("Cannot operate on a closed JSON stream");
31+
throw new RuntimeException('Cannot operate on a closed JSON stream');
3232
}
3333

3434
return $this->encoder;
@@ -80,7 +80,7 @@ public function seek($offset, $whence = SEEK_SET)
8080
if ($whence === SEEK_CUR) {
8181
$position = max(0, $this->cursor + (int) $offset);
8282
} elseif ($whence === SEEK_END) {
83-
throw new \RuntimeException("Cannot set cursor position from the end of a JSON stream");
83+
throw new \RuntimeException('Cannot set cursor position from the end of a JSON stream');
8484
} else {
8585
$position = max(0, (int) $offset);
8686
}

tests/tests/JsonEncoderTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Violet\StreamingJsonEncoder;
44

55
use PHPUnit\Framework\TestCase;
6-
use Symfony\CS\Tokenizer\Token;
76
use Violet\StreamingJsonEncoder\Test\SerializableData;
87

98
/**
@@ -47,7 +46,7 @@ public function testPrettyPrint()
4746
[
4847
'foo',
4948
],
50-
]
49+
],
5150
];
5251

5352
$this->assertEncodingResult($expectedJson, $array, $array, JSON_PRETTY_PRINT);
@@ -108,7 +107,7 @@ public function testJsonSerializable()
108107
$serializable = new SerializableData(new SerializableData([
109108
'key 1' => new SerializableData([
110109
'sub key 1' => 'sub value 1',
111-
])
110+
]),
112111
]));
113112

114113
$this->assertEncodingResult($expectedJson, ['key 1' => ['sub key 1' => 'sub value 1']], $serializable);
@@ -133,9 +132,9 @@ public function testNullOnInvalid()
133132
$expectedJson = '{"key 1":null,"key 2":{"one":"two"}}';
134133
$array = [
135134
'key 1' => fopen('php://memory', 'r'),
136-
"key 2" => $generator(),
135+
'key 2' => $generator(),
137136
];
138-
$result = ['key 1' => null, "key 2" => ['one' => 'two']];
137+
$result = ['key 1' => null, 'key 2' => ['one' => 'two']];
139138

140139
$encoder = $this->assertEncodingResult($expectedJson, $result, $array, JSON_PARTIAL_OUTPUT_ON_ERROR);
141140
$this->assertSame([
@@ -171,7 +170,7 @@ public function getSimpleTestValues()
171170
'key 1' => 'value 1',
172171
'key 2' => 'value 2',
173172
]],
174-
[['value 1', 'value 2', 'value 3']]
173+
[['value 1', 'value 2', 'value 3']],
175174
];
176175
}
177176

tests/tests/JsonStreamTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public function testExactReads()
1717
{
1818
$stream = new JsonStream(['key' => 'value']);
1919

20-
$this->assertSame(false, $stream->eof());
20+
$this->assertFalse($stream->eof());
2121
$this->assertSame(0, $stream->tell());
2222
$this->assertSame('{', $stream->read(1));
2323
$this->assertSame(1, $stream->tell());
24-
$this->assertSame(false, $stream->eof());
24+
$this->assertFalse($stream->eof());
2525
$this->assertSame('"key":"value"}', $stream->read(14));
2626
$this->assertSame(15, $stream->tell());
27-
$this->assertSame(true, $stream->eof());
27+
$this->assertTrue($stream->eof());
2828
$this->assertSame('', $stream->read(1));
2929
}
3030

@@ -67,13 +67,13 @@ public function testConstantValueMethods()
6767
{
6868
$stream = new JsonStream('value');
6969

70-
$this->assertSame(null, $stream->detach());
71-
$this->assertSame(null, $stream->getSize());
72-
$this->assertSame(true, $stream->isSeekable());
73-
$this->assertSame(false, $stream->isWritable());
74-
$this->assertSame(true, $stream->isReadable());
70+
$this->assertNull($stream->detach());
71+
$this->assertNull($stream->getSize());
72+
$this->assertTrue($stream->isSeekable());
73+
$this->assertFalse($stream->isWritable());
74+
$this->assertTrue($stream->isReadable());
7575
$this->assertSame([], $stream->getMetadata());
76-
$this->assertSame(null, $stream->getMetadata('seekable'));
76+
$this->assertNull($stream->getMetadata('seekable'));
7777
}
7878

7979
public function testWriting()

0 commit comments

Comments
 (0)