Skip to content

Commit 9e1971c

Browse files
authored
Improve coding standard (#1136)
* Require arrow functions where possible * Require single-quote use where possible * Remove unnecessary properties in sniff declaration
1 parent 61c0711 commit 9e1971c

File tree

7 files changed

+21
-45
lines changed

7 files changed

+21
-45
lines changed

phpcs.xml.dist

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
<!-- Exclude sniffs that cause a huge diff - enable separately -->
6464
<!-- ********************************************************* -->
6565
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectAnnotationsGroup" />
66-
<exclude name="Squiz.Strings.DoubleQuoteUsage" />
6766

6867

6968
<!-- ********************* -->
@@ -78,9 +77,13 @@
7877
</rule>
7978

8079

81-
<!-- ***************************************************** -->
80+
<!-- **************************************** -->
81+
<!-- Enable rules not enforced by Doctrine CS -->
82+
<!-- **************************************** -->
83+
84+
<!-- Require arrow functions where possible -->
85+
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction"/>
8286
<!-- Forbid fully qualified names even for colliding names -->
83-
<!-- ***************************************************** -->
8487
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
8588
<properties>
8689
<property name="allowFallbackGlobalConstants" value="false"/>
@@ -96,41 +99,16 @@
9699
</rule>
97100

98101

99-
<!-- **************************************************************************** -->
100-
<!-- Exclude BC breaking type hints for parameters, properties, and return values -->
101-
<!-- **************************************************************************** -->
102+
<!-- ****************************************************** -->
103+
<!-- Don't require annotations to specify traversable types -->
104+
<!-- ****************************************************** -->
102105
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
103-
<properties>
104-
<!-- Requires PHP 8.0 -->
105-
<property name="enableMixedTypeHint" value="false" />
106-
<!-- Requires PHP 8.0 -->
107-
<property name="enableUnionTypeHint" value="false" />
108-
</properties>
109-
110106
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
111107
</rule>
112-
113108
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
114-
<properties>
115-
<!-- Requires PHP 8.0 -->
116-
<property name="enableMixedTypeHint" value="false" />
117-
<!-- Requires PHP 8.0 -->
118-
<property name="enableUnionTypeHint" value="false" />
119-
</properties>
120-
121109
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
122110
</rule>
123-
124111
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
125-
<properties>
126-
<!-- Requires PHP 8.0 -->
127-
<property name="enableStaticTypeHint" value="false" />
128-
<!-- Requires PHP 8.0 -->
129-
<property name="enableMixedTypeHint" value="false" />
130-
<!-- Requires PHP 8.0 -->
131-
<property name="enableUnionTypeHint" value="false" />
132-
</properties>
133-
134112
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
135113
</rule>
136114

src/GridFS/Bucket.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function delete($id)
232232
*/
233233
public function downloadToStream($id, $destination)
234234
{
235-
if (! is_resource($destination) || get_resource_type($destination) != "stream") {
235+
if (! is_resource($destination) || get_resource_type($destination) != 'stream') {
236236
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
237237
}
238238

@@ -272,7 +272,7 @@ public function downloadToStream($id, $destination)
272272
*/
273273
public function downloadToStreamByName(string $filename, $destination, array $options = [])
274274
{
275-
if (! is_resource($destination) || get_resource_type($destination) != "stream") {
275+
if (! is_resource($destination) || get_resource_type($destination) != 'stream') {
276276
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
277277
}
278278

@@ -616,7 +616,7 @@ public function rename($id, string $newFilename)
616616
*/
617617
public function uploadFromStream(string $filename, $source, array $options = [])
618618
{
619-
if (! is_resource($source) || get_resource_type($source) != "stream") {
619+
if (! is_resource($source) || get_resource_type($source) != 'stream') {
620620
throw InvalidArgumentException::invalidType('$source', $source, 'resource');
621621
}
622622

@@ -685,7 +685,7 @@ private function getFilesNamespace(): string
685685
*/
686686
private function getRawFileDocumentForStream($stream): object
687687
{
688-
if (! is_resource($stream) || get_resource_type($stream) != "stream") {
688+
if (! is_resource($stream) || get_resource_type($stream) != 'stream') {
689689
throw InvalidArgumentException::invalidType('$stream', $stream, 'resource');
690690
}
691691

tests/DocumentationExamplesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ private function commitWithRetry3(\MongoDB\Driver\Session $session): void
14031403
private function updateEmployeeInfo3(\MongoDB\Client $client, \MongoDB\Driver\Session $session): void
14041404
{
14051405
$session->startTransaction([
1406-
'readConcern' => new \MongoDB\Driver\ReadConcern("snapshot"),
1406+
'readConcern' => new \MongoDB\Driver\ReadConcern('snapshot'),
14071407
'readPrefernece' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::PRIMARY),
14081408
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
14091409
]);

tests/FunctionalTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public static function isCryptSharedLibAvailable(): bool
534534
/** @see https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/mongocryptd/ */
535535
public static function isMongocryptdAvailable(): bool
536536
{
537-
$paths = explode(PATH_SEPARATOR, getenv("PATH"));
537+
$paths = explode(PATH_SEPARATOR, getenv('PATH'));
538538

539539
foreach ($paths as $path) {
540540
if (is_executable($path . DIRECTORY_SEPARATOR . 'mongocryptd')) {

tests/GridFS/BucketFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function testDeleteStillRemovesChunksIfFileDoesNotExist($input, $expected
140140

141141
public function testDownloadingFileWithMissingChunk(): void
142142
{
143-
$id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar"));
143+
$id = $this->bucket->uploadFromStream('filename', $this->createStream('foobar'));
144144

145145
$this->chunksCollection->deleteOne(['files_id' => $id, 'n' => 0]);
146146

@@ -151,7 +151,7 @@ public function testDownloadingFileWithMissingChunk(): void
151151

152152
public function testDownloadingFileWithUnexpectedChunkIndex(): void
153153
{
154-
$id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar"));
154+
$id = $this->bucket->uploadFromStream('filename', $this->createStream('foobar'));
155155

156156
$this->chunksCollection->updateOne(
157157
['files_id' => $id, 'n' => 0],
@@ -165,7 +165,7 @@ public function testDownloadingFileWithUnexpectedChunkIndex(): void
165165

166166
public function testDownloadingFileWithUnexpectedChunkSize(): void
167167
{
168-
$id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar"));
168+
$id = $this->bucket->uploadFromStream('filename', $this->createStream('foobar'));
169169

170170
$this->chunksCollection->updateOne(
171171
['files_id' => $id, 'n' => 0],

tests/PedantryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ public function testMethodsAreOrderedAlphabeticallyByVisibility($className): voi
3232

3333
$methods = array_filter(
3434
$methods,
35-
function (ReflectionMethod $method) use ($class) {
36-
return $method->getDeclaringClass() == $class // Exclude inherited methods
37-
&& $method->getFileName() === $class->getFileName(); // Exclude methods inherited from traits
38-
},
35+
fn (ReflectionMethod $method) => $method->getDeclaringClass() == $class // Exclude inherited methods
36+
&& $method->getFileName() === $class->getFileName(), // Exclude methods inherited from traits
3937
);
4038

4139
$getSortValue = function (ReflectionMethod $method) {

tools/detect-extension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function grepIniFile(string $filename, string $extension): int
8585
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
8686
$zts = PHP_ZTS ? 'Thread Safe (TS)' : 'Non Thread Safe (NTS)';
8787
$arch = PHP_INT_SIZE === 8 ? 'x64' : 'x86';
88-
$dll = sprintf("%d.%d %s %s", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, $zts, $arch);
88+
$dll = sprintf('%d.%d %s %s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, $zts, $arch);
8989

9090
printf("You likely need to download a Windows DLL for: %s\n", $dll);
9191
printf("Windows DLLs should be available from: https://pecl.php.net/package/%s\n", $extension);

0 commit comments

Comments
 (0)