Skip to content

Switch to phpcs and upgrade codebase #2596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@ on:
pull_request:

jobs:
php-cs-fixer:
runs-on: ubuntu-latest
env:
PHP_CS_FIXER_VERSION: v3.6.0
strategy:
matrix:
php:
- '8.1'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl,mbstring
tools: php-cs-fixer:${{ env.PHP_CS_FIXER_VERSION }}
coverage: none
- name: Run PHP-CS-Fixer Fix, version ${{ env.PHP_CS_FIXER_VERSION }}
run: php-cs-fixer fix --dry-run --diff --ansi

build:
runs-on: ${{ matrix.os }}
name: PHP v${{ matrix.php }} with MongoDB ${{ matrix.mongodb }}
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Coding Standards"

on:
push:
branches:
tags:
pull_request:

env:
PHP_VERSION: "8.2"
DRIVER_VERSION: "stable"

jobs:
phpcs:
name: "phpcs"
runs-on: "ubuntu-22.04"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ env.PHP_VERSION }}
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
key: "extcache-v1"

- name: Cache extensions
uses: actions/cache@v3
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
php-version: "${{ env.PHP_VERSION }}"
tools: "cs2pr"

- name: "Show driver information"
run: "php --ri mongodb"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@2.2.0"
with:
composer-options: "--no-suggest"

# The -q option is required until phpcs v4 is released
- name: "Run PHP_CodeSniffer"
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
.DS_Store
.idea/
.phpunit.result.cache
/.php-cs-fixer.php
/.php-cs-fixer.cache
.phpcs-cache
/vendor
composer.lock
composer.phar
Expand Down
187 changes: 0 additions & 187 deletions .php-cs-fixer.dist.php

This file was deleted.

10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"require-dev": {
"phpunit/phpunit": "^9.5.10",
"orchestra/testbench": "^8.0",
"mockery/mockery": "^1.4.4"
"mockery/mockery": "^1.4.4",
"doctrine/coding-standard": "12.0.x-dev"
},
"replace": {
"jenssegers/mongodb": "self.version"
Expand All @@ -56,5 +57,10 @@
]
}
},
"minimum-stability": "dev"
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
38 changes: 38 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="." />
<arg name="extensions" value="php" />
<arg name="parallel" value="80" />
<arg name="cache" value=".phpcs-cache" />
<arg name="colors" />

<!-- Ignore warnings (n), show progress of the run (p), and show sniff names (s) -->
<arg value="nps"/>

<file>src</file>
<file>tests</file>

<!-- Target minimum supported PHP version -->
<config name="php_version" value="80100"/>

<!-- ****************************************** -->
<!-- Import rules from doctrine/coding-standard -->
<!-- ****************************************** -->
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing"/>
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<exclude name="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>
<exclude name="SlevomatCodingStandard.Functions.StaticClosure"/>
<exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat.DisallowedShortNullable"/>

<!-- Model properties use snake_case -->
<exclude name="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>

<!-- Type changes needs to be synchronized with laravel/framework -->
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
</rule>
</ruleset>
19 changes: 9 additions & 10 deletions src/Auth/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MongoDB\Laravel\Auth;

use DateTime;
Expand All @@ -8,11 +10,12 @@
use Illuminate\Support\Facades\Date;
use MongoDB\BSON\UTCDateTime;

use function date_default_timezone_get;
use function is_array;

class DatabaseTokenRepository extends BaseDatabaseTokenRepository
{
/**
* @inheritdoc
*/
/** @inheritdoc */
protected function getPayload($email, $token)
{
return [
Expand All @@ -22,19 +25,15 @@ protected function getPayload($email, $token)
];
}

/**
* @inheritdoc
*/
/** @inheritdoc */
protected function tokenExpired($createdAt)
{
$createdAt = $this->convertDateTime($createdAt);

return parent::tokenExpired($createdAt);
}

/**
* @inheritdoc
*/
/** @inheritdoc */
protected function tokenRecentlyCreated($createdAt)
{
$createdAt = $this->convertDateTime($createdAt);
Expand All @@ -50,7 +49,7 @@ private function convertDateTime($createdAt)
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$createdAt = $date->format('Y-m-d H:i:s');
} elseif (is_array($createdAt) && isset($createdAt['date'])) {
$date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC'));
$date = new DateTime($createdAt['date'], new DateTimeZone($createdAt['timezone'] ?? 'UTC'));
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$createdAt = $date->format('Y-m-d H:i:s');
}
Expand Down
Loading