Skip to content
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

feat: add ecs & phpstan code analysis #23

Open
wants to merge 3 commits into
base: v3-dev
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Code Analysis

on:
pull_request: null
push:
branches:
- v3-dev
workflow_dispatch:
permissions:
contents: read
jobs:
code_analysis:
strategy:
fail-fast: false
matrix:
actions:
- name: 'PHPStan'
run: composer phpstan
- name: 'Coding Standards'
run: composer fix-cs
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip'
ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M
tools: composer:v2
- name: Install Composer dependencies
run: composer install --no-interaction --no-ansi --no-progress
- run: ${{ matrix.actions.run }}
94 changes: 56 additions & 38 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
{
"name": "doublesecretagency/craft-cpcss",
"description": "Add custom CSS to your Control Panel.",
"type": "craft-plugin",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"cp-css",
"css"
],
"support": {
"docs": "https://github.com/doublesecretagency/craft-cpcss/blob/v3/README.md",
"issues": "https://github.com/doublesecretagency/craft-cpcss/issues"
},
"license": "MIT",
"authors": [
{
"name": "Double Secret Agency",
"homepage": "https://www.doublesecretagency.com/plugins"
}
],
"require": {
"craftcms/cms": "^5.0.0-beta",
"nystudio107/craft-code-editor": "^1.0.7"
},
"autoload": {
"psr-4": {
"doublesecretagency\\cpcss\\": "src/"
}
},
"extra": {
"name": "Control Panel CSS",
"handle": "cp-css",
"schemaVersion": "2.0.0",
"changelogUrl": "https://raw.githubusercontent.com/doublesecretagency/craft-cpcss/v3/CHANGELOG.md",
"class": "doublesecretagency\\cpcss\\CpCss"
"name": "doublesecretagency/craft-cpcss",
"description": "Add custom CSS to your Control Panel.",
"type": "craft-plugin",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"cp-css",
"css"
],
"support": {
"docs": "https://github.com/doublesecretagency/craft-cpcss/blob/v3/README.md",
"issues": "https://github.com/doublesecretagency/craft-cpcss/issues"
},
"license": "MIT",
"authors": [
{
"name": "Double Secret Agency",
"homepage": "https://www.doublesecretagency.com/plugins"
}
],
"require": {
"craftcms/cms": "^5.0.0-beta",
"nystudio107/craft-code-editor": "^1.0.7"
},
"autoload": {
"psr-4": {
"doublesecretagency\\cpcss\\": "src/"
}
},
"extra": {
"name": "Control Panel CSS",
"handle": "cp-css",
"schemaVersion": "2.0.0",
"changelogUrl": "https://raw.githubusercontent.com/doublesecretagency/craft-cpcss/v3/CHANGELOG.md",
"class": "doublesecretagency\\cpcss\\CpCss"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"craftcms/rector": "dev-main"
},
"scripts": {
"phpstan": "phpstan --ansi --memory-limit=1G",
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --fix --ansi"
},
"config": {
"allow-plugins": {
"craftcms/plugin-installer": true,
"yiisoft/yii2-composer": true
},
"optimize-autoloader": true,
"sort-packages": true
}
}
13 changes: 13 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);
$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 5
paths:
- src
5 changes: 1 addition & 4 deletions src/CpCss.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
class CpCss extends Plugin
{

/**
* @var CpCss Self-referential plugin property.
*/
Expand Down Expand Up @@ -54,7 +53,7 @@ public function init(): void
Event::on(
View::class,
View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
function (TemplateEvent $event) {
function(TemplateEvent $event) {

// Get view
$view = Craft::$app->getView();
Expand All @@ -69,7 +68,6 @@ function (TemplateEvent $event) {
if ($css) {
$view->registerCss($css);
}

}
);
}
Expand All @@ -96,5 +94,4 @@ protected function settingsHtml(): ?string
'docsUrl' => $this->documentationUrl,
]);
}

}
2 changes: 0 additions & 2 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
class Settings extends Model
{

/**
* @var string Path for the CSS file to load in the control panel.
*/
Expand All @@ -34,5 +33,4 @@ class Settings extends Model
* @var bool Whether to enable the hash-based cache busting.
*/
public bool $cacheBusting = true;

}
11 changes: 0 additions & 11 deletions src/web/assets/CustomAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
class CustomAssets extends AssetBundle
{

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -69,7 +68,6 @@ public function init(): void
// Reference file without a hash
$this->css[] = $file;
}

}
}

Expand All @@ -95,16 +93,7 @@ private function _addHash(string $file): string
// Get hash of contents
$hash = @sha1($contents);

// If unable to hash file contents
if (!$hash) {
// Log warning
Craft::warning("Can't bust cache for CP CSS, unable to hash contents of $file");
// Return file without hash
return $file;
}

// Return file with hash
return "{$file}?e={$hash}";
}

}