Skip to content

Commit

Permalink
Improve coding standard (#1136)
Browse files Browse the repository at this point in the history
* Require arrow functions where possible

* Require single-quote use where possible

* Remove unnecessary properties in sniff declaration
  • Loading branch information
alcaeus committed Jul 20, 2023
1 parent 61c0711 commit 9e1971c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 45 deletions.
40 changes: 9 additions & 31 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<!-- Exclude sniffs that cause a huge diff - enable separately -->
<!-- ********************************************************* -->
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectAnnotationsGroup" />
<exclude name="Squiz.Strings.DoubleQuoteUsage" />


<!-- ********************* -->
Expand All @@ -78,9 +77,13 @@
</rule>


<!-- ***************************************************** -->
<!-- **************************************** -->
<!-- Enable rules not enforced by Doctrine CS -->
<!-- **************************************** -->

<!-- Require arrow functions where possible -->
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction"/>
<!-- Forbid fully qualified names even for colliding names -->
<!-- ***************************************************** -->
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="allowFallbackGlobalConstants" value="false"/>
Expand All @@ -96,41 +99,16 @@
</rule>


<!-- **************************************************************************** -->
<!-- Exclude BC breaking type hints for parameters, properties, and return values -->
<!-- **************************************************************************** -->
<!-- ****************************************************** -->
<!-- Don't require annotations to specify traversable types -->
<!-- ****************************************************** -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<properties>
<!-- Requires PHP 8.0 -->
<property name="enableMixedTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
<property name="enableUnionTypeHint" value="false" />
</properties>

<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<!-- Requires PHP 8.0 -->
<property name="enableMixedTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
<property name="enableUnionTypeHint" value="false" />
</properties>

<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<!-- Requires PHP 8.0 -->
<property name="enableStaticTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
<property name="enableMixedTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
<property name="enableUnionTypeHint" value="false" />
</properties>

<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
</rule>

Expand Down
8 changes: 4 additions & 4 deletions src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function delete($id)
*/
public function downloadToStream($id, $destination)
{
if (! is_resource($destination) || get_resource_type($destination) != "stream") {
if (! is_resource($destination) || get_resource_type($destination) != 'stream') {
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
}

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

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

Expand Down Expand Up @@ -685,7 +685,7 @@ private function getFilesNamespace(): string
*/
private function getRawFileDocumentForStream($stream): object
{
if (! is_resource($stream) || get_resource_type($stream) != "stream") {
if (! is_resource($stream) || get_resource_type($stream) != 'stream') {
throw InvalidArgumentException::invalidType('$stream', $stream, 'resource');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/DocumentationExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ private function commitWithRetry3(\MongoDB\Driver\Session $session): void
private function updateEmployeeInfo3(\MongoDB\Client $client, \MongoDB\Driver\Session $session): void
{
$session->startTransaction([
'readConcern' => new \MongoDB\Driver\ReadConcern("snapshot"),
'readConcern' => new \MongoDB\Driver\ReadConcern('snapshot'),
'readPrefernece' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::PRIMARY),
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public static function isCryptSharedLibAvailable(): bool
/** @see https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/mongocryptd/ */
public static function isMongocryptdAvailable(): bool
{
$paths = explode(PATH_SEPARATOR, getenv("PATH"));
$paths = explode(PATH_SEPARATOR, getenv('PATH'));

foreach ($paths as $path) {
if (is_executable($path . DIRECTORY_SEPARATOR . 'mongocryptd')) {
Expand Down
6 changes: 3 additions & 3 deletions tests/GridFS/BucketFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testDeleteStillRemovesChunksIfFileDoesNotExist($input, $expected

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

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

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

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

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

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

$this->chunksCollection->updateOne(
['files_id' => $id, 'n' => 0],
Expand Down
6 changes: 2 additions & 4 deletions tests/PedantryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public function testMethodsAreOrderedAlphabeticallyByVisibility($className): voi

$methods = array_filter(
$methods,
function (ReflectionMethod $method) use ($class) {
return $method->getDeclaringClass() == $class // Exclude inherited methods
&& $method->getFileName() === $class->getFileName(); // Exclude methods inherited from traits
},
fn (ReflectionMethod $method) => $method->getDeclaringClass() == $class // Exclude inherited methods
&& $method->getFileName() === $class->getFileName(), // Exclude methods inherited from traits
);

$getSortValue = function (ReflectionMethod $method) {
Expand Down
2 changes: 1 addition & 1 deletion tools/detect-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function grepIniFile(string $filename, string $extension): int
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$zts = PHP_ZTS ? 'Thread Safe (TS)' : 'Non Thread Safe (NTS)';
$arch = PHP_INT_SIZE === 8 ? 'x64' : 'x86';
$dll = sprintf("%d.%d %s %s", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, $zts, $arch);
$dll = sprintf('%d.%d %s %s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, $zts, $arch);

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

0 comments on commit 9e1971c

Please sign in to comment.