Skip to content

Commit

Permalink
Enable PHP-CS-Fixer in Github Action (gnikyt#883)
Browse files Browse the repository at this point in the history
* Enable PHP-CS-Fixer.

* Fix all code violations.
  • Loading branch information
lucasmichot authored Jul 12, 2021
1 parent ed99e4d commit 7ec27fe
Show file tree
Hide file tree
Showing 46 changed files with 268 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.styleci.yml export-ignore
.php-cs-fixer.dist.php export-ignore
CODE_OF_CONDUCT.md export-ignore
phpunit.xml export-ignore
CONTRIBUTING.md export-ignore
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: PHP Lint

on: [ push, pull_request ]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v2

- name: Check for code style violation with PHP-CS-Fixer
uses: OskarStark/[email protected]
with:
args: --diff --dry-run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/build
/vendor
composer.lock
.php-cs-fixer.cache
.phpunit.result.cache
63 changes: 63 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$rules = [
'@PSR2' => true,
'@PSR12' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => true,
'blank_line_after_namespace' => true,
'blank_line_before_statement' => true,
'cast_spaces' => true,
'concat_space' => [
'spacing' => 'none',
],
'ereg_to_preg' => true,
'is_null' => true,
'line_ending' => true,
'modernize_types_casting' => true,
'no_blank_lines_after_phpdoc' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'phpdoc_align' => false,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'self_accessor' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
];

$finder = Finder::create()->in(__DIR__)
->notPath([
'src/ShopifyApp/resources/config/shopify-app.php',
]);

return (new Config())
->setRules($rules)
->setFinder($finder)
->setRiskyAllowed(true);
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

18 changes: 12 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Its best to:
1. Fork the repository (see adding upstream below)
2. Create a branch such as `cool-new-feature`
3. Create your code
4. Create and run successfull tests (see testing below)
4. Create and run successful tests (see testing below)
5. Submit a pull request

## Found a bug?
Expand All @@ -38,7 +38,7 @@ Its best to:
1. Fork the repository (see adding upstream below)
2. Create a branch such as `issue-(issuenumber)-fix`
3. Create your code
4. Create and run successfull tests (see testing below)
4. Create and run successful tests (see testing below)
5. Submit a pull request
6. Comment on the issue

Expand All @@ -58,11 +58,17 @@ You can then update by simply running:

#### Locally

We use PHPUnit to run tests. Simply run `composer install` and a symlink `phpunit` should be located in the `bin` directory.
We use PHPUnit to run tests. Simply run `composer install`.

Next, run `bin/phpunit` and the rest will be taken care of. Upon any pull requests and merges, TravisCI will check the code to ensure all test suites pass.
Next, run `vendor/bin/phpunit` and the rest will be taken care of. Upon any pull requests and merges.

For quicker tests, be sure to disable coverage with `bin/php --no-coverage`.
For quicker tests, be sure to disable coverage with `vendor/bin/phpunit --no-coverage`.

### Checking style

We use PHP-CS-Fixer to check for code style violations.

To lint the code, simply run `composer lint`.

#### Actions

Expand All @@ -75,4 +81,4 @@ We also utilize Github Actions. Currently it will:

-----

Thats it! Enjoy.
That's it! Enjoy.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"require-dev": {
"ergebnis/composer-normalize": "^2.8",
"friendsofphp/php-cs-fixer": "^3.0",
"mockery/mockery": "^1.0",
"orchestra/database": "~3.8 || ~4.0 || ~5.0 || ~6.0",
"orchestra/testbench": "~3.8 || ~4.0 || ~5.0 || ~6.0",
Expand Down Expand Up @@ -61,6 +62,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"lint": "vendor/bin/php-cs-fixer fix",
"test": "vendor/bin/phpunit",
"test-html-cov": "vendor/bin/phpunit --coverage-html ./build/html/",
"test-no-cov": "vendor/bin/phpunit --no-coverage"
Expand Down
12 changes: 6 additions & 6 deletions src/ShopifyApp/Actions/InstallShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function __invoke(ShopDomain $shopDomain, ?string $code): array
if (empty($code)) {
return [
'completed' => false,
'url' => $apiHelper->buildAuthUrl($grantMode, Util::getShopifyConfig('api_scopes', $shop)),
'shop_id' => $shop->getId(),
'url' => $apiHelper->buildAuthUrl($grantMode, Util::getShopifyConfig('api_scopes', $shop)),
'shop_id' => $shop->getId(),
];
}

Expand All @@ -90,15 +90,15 @@ public function __invoke(ShopDomain $shopDomain, ?string $code): array

return [
'completed' => true,
'url' => null,
'shop_id' => $shop->getId(),
'url' => null,
'shop_id' => $shop->getId(),
];
} catch (Exception $e) {
// Just return the default setting
return [
'completed' => false,
'url' => null,
'shop_id' => null,
'url' => null,
'shop_id' => null,
];
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ShopifyApp/Contracts/Commands/Shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Shop
*
* @param ShopDomainValue $domain
* @param AccessTokenValue $token
*
* @return ShopIdValue
*/
public function make(ShopDomainValue $domain, AccessTokenValue $token): ShopIdValue;
Expand Down
2 changes: 1 addition & 1 deletion src/ShopifyApp/Http/Middleware/AuthProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function handle(Request $request, Closure $next)
// Build a local signature
$signatureLocal = Util::createHmac(
[
'data' => $query,
'data' => $query,
'buildQuery' => true,
],
Util::getShopifyConfig('api_secret', $shop)
Expand Down
4 changes: 2 additions & 2 deletions src/ShopifyApp/Http/Middleware/AuthWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function handle(Request $request, Closure $next)
$data = $request->getContent();
$hmacLocal = Util::createHmac(
[
'data' => $data,
'raw' => true,
'data' => $data,
'raw' => true,
'encode' => true,
],
Util::getShopifyConfig('api_secret', $shop)
Expand Down
6 changes: 3 additions & 3 deletions src/ShopifyApp/Http/Middleware/VerifyShopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected function tokenRedirect(Request $request): RedirectResponse
return Redirect::route(
Util::getShopifyConfig('route_names.authenticate.token'),
[
'shop' => ShopDomain::fromRequest($request)->toNative(),
'shop' => ShopDomain::fromRequest($request)->toNative(),
'target' => $target,
]
);
Expand Down Expand Up @@ -404,8 +404,8 @@ protected function getRequestData(Request $request, string $source): array
$timestamp = $request->header('X-Shop-Time');

$verify = [
'shop' => $shop,
'hmac' => $signature,
'shop' => $shop,
'hmac' => $signature,
'timestamp' => $timestamp,
];

Expand Down
12 changes: 6 additions & 6 deletions src/ShopifyApp/Http/Requests/StoreUsageCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function withValidator(Validator $validator): void
$validator->after(function (Validator $validator) {
// Get the input values needed
$data = [
'price' => $this->request->get('price'),
'price' => $this->request->get('price'),
'description' => $this->request->get('description'),
'signature' => $this->request->get('signature'),
'signature' => $this->request->get('signature'),
];
if ($this->request->has('redirect')) {
$data['redirect'] = $this->request->get('redirect');
Expand All @@ -49,7 +49,7 @@ public function withValidator(Validator $validator): void
// Confirm the charge hasn't been tampered with
$signatureLocal = Util::createHmac(
[
'data' => $data,
'data' => $data,
'buildQuery' => true,
],
Util::getShopifyConfig('api_secret')
Expand All @@ -69,10 +69,10 @@ public function withValidator(Validator $validator): void
public function rules(): array
{
return [
'signature' => 'required|string',
'price' => 'required|numeric',
'signature' => 'required|string',
'price' => 'required|numeric',
'description' => 'required|string',
'redirect' => 'nullable|string',
'redirect' => 'nullable|string',
];
}
}
2 changes: 1 addition & 1 deletion src/ShopifyApp/Macros/TokenUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function generateParams(string $route, $params = [], bool $absolute = tru
return [
Util::getShopifyConfig('route_names.authenticate.token'),
[
'shop' => ShopDomain::fromRequest(Request::instance())->toNative(),
'shop' => ShopDomain::fromRequest(Request::instance())->toNative(),
'target' => URL::route($route, $params, $absolute),
],
];
Expand Down
2 changes: 2 additions & 0 deletions src/ShopifyApp/Objects/Transfers/AbstractTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __get(string $key): void
{
// Does not exist, throw exception
$className = get_class($this);

throw new Exception("Property {$key} does not exist on transfer class {$className}");
}

Expand All @@ -42,6 +43,7 @@ public function __set(string $key, $value): void
{
// Not allowed, throw exception
$className = get_class($this);

throw new Exception("Setting property {$key} for transfer class {$className} is not allowed");
}

Expand Down
14 changes: 7 additions & 7 deletions src/ShopifyApp/Objects/Transfers/PlanDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ final class PlanDetails extends AbstractTransfer
public function toArray(): array
{
return [
'name' => $this->name,
'price' => $this->price,
'interval' => $this->interval,
'test' => $this->test,
'trial_days' => $this->trialDays,
'return_url' => $this->returnUrl,
'terms' => $this->terms,
'name' => $this->name,
'price' => $this->price,
'interval' => $this->interval,
'test' => $this->test,
'trial_days' => $this->trialDays,
'return_url' => $this->returnUrl,
'terms' => $this->terms,
'capped_amount' => $this->cappedAmount,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/ShopifyApp/Objects/Values/SessionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function fromNative($native)
*
* @return bool
*/
public function isValid(?SessionContext $previousContext = null): bool
public function isValid(?self $previousContext = null): bool
{
// Confirm access token and session token are good
$tokenCheck = ! $this->getAccessToken()->isEmpty() && ! $this->getSessionToken()->isNull();
Expand Down
Loading

0 comments on commit 7ec27fe

Please sign in to comment.