From 4817a9bf802c77173be5dfdb0fa1e2a29a1cf641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 21 Aug 2022 20:01:54 +0200 Subject: [PATCH 1/3] Minor CS cleanup --- src/ChartBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChartBox.php b/src/ChartBox.php index 2cffe64..3fa0b06 100644 --- a/src/ChartBox.php +++ b/src/ChartBox.php @@ -8,7 +8,7 @@ use Atk4\Ui\View; /** - * Implements a box that contains a chart. + * Box that contains a chart. */ class ChartBox extends View { From 554693f5604c931a6a0c9761909c0bfe5f3e676d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 26 Aug 2022 17:20:33 +0200 Subject: [PATCH 2/3] Enable phpstan bleading edge and strict rules --- .github/workflows/build-docs.yml | 15 +++++++++++++++ .php-cs-fixer.dist.php | 9 +-------- codecov.yml | 12 ------------ composer.json | 1 + phpstan.neon.dist | 25 +++++++------------------ src/Chart.php | 1 + src/PieChart.php | 1 + 7 files changed, 26 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/build-docs.yml delete mode 100644 codecov.yml diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml new file mode 100644 index 0000000..ab60038 --- /dev/null +++ b/.github/workflows/build-docs.yml @@ -0,0 +1,15 @@ +name: Build Docs + +on: + push: + branches: + - develop + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + - name: Run Release Drafter + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 9dfc26b..f86b629 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,11 +2,7 @@ $finder = PhpCsFixer\Finder::create() ->in([__DIR__]) - ->exclude([ - 'cache', - 'build', - 'vendor', - ]); + ->exclude(['vendor']); return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) @@ -48,9 +44,6 @@ 'no_superfluous_elseif' => false, 'ordered_class_elements' => false, 'php_unit_internal_class' => false, - 'php_unit_test_case_static_method_calls' => [ - 'call_type' => 'this', - ], 'php_unit_test_class_requires_covers' => false, 'phpdoc_add_missing_param_annotation' => false, 'return_assignment' => false, diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index 1f1d4d4..0000000 --- a/codecov.yml +++ /dev/null @@ -1,12 +0,0 @@ -ignore: - - docs -comment: false -coverage: - status: - project: - default: - target: auto - threshold: 0.025 - patch: false - changes: false - diff --git a/composer.json b/composer.json index 2eab6b8..01eeaf7 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.0", "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-strict-rules": "^1.3", "phpunit/phpunit": "^9.5.5" }, "minimum-stability": "dev", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 09b8f29..90a63b9 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,29 +1,18 @@ +includes: + - phar://phpstan.phar/conf/bleedingEdge.neon + parameters: level: 6 paths: - ./ excludePaths: - - cache/ - - build/ - vendor/ - # TODO review once we drop PHP 7.x support - treatPhpDocTypesAsCertain: false - - # some extra rules - checkAlwaysTrueCheckTypeFunctionCall: true - checkAlwaysTrueInstanceof: true - checkAlwaysTrueStrictComparison: true - checkExplicitMixedMissingReturn: true - checkFunctionNameCase: true - # TODO checkMissingClosureNativeReturnTypehintRule: true - reportMaybesInMethodSignatures: true - reportStaticMethodSignatures: true - checkTooWideReturnTypesInProtectedAndPublicMethods: true - checkMissingIterableValueType: false # TODO - ignoreErrors: - #- '~^Unsafe usage of new static\(\)\.$~' + - '~^(Property .+ has|Method .+\(\) (has parameter \$.+ with|return type has)) no value type specified in iterable type .+\.~' + + # relax strict rules + - '~^Only booleans are allowed in .+, .+ given( on the (left|right) side)?\.~' # for src/Chart.php - '~^Call to an undefined method Atk4\\Data\\Model::expr\(\)\.$~' diff --git a/src/Chart.php b/src/Chart.php index 06532f8..c8e3ee8 100644 --- a/src/Chart.php +++ b/src/Chart.php @@ -148,6 +148,7 @@ public function setModel(Model $model, array $columns = []): void public function withCurrency(string $char = '€', string $axis = 'y') { // magic regex adds commas as thousand separators: http://009co.com/?p=598 + $options = []; $options['scales'][$axis . 'Axes'] = [['ticks' => [ 'userCallback' => new JsExpression('{}', ['function(value) { value=Math.round(value*1000000)/1000000; return "' . $char . ' " + value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }']), diff --git a/src/PieChart.php b/src/PieChart.php index 8c448f6..dd51429 100644 --- a/src/PieChart.php +++ b/src/PieChart.php @@ -71,6 +71,7 @@ public function setModel(Model $model, array $columns = []): void */ public function withCurrency(string $char = '€', string $axis = 'y') { + $options = []; $options['tooltips'] = [ // 'enabled' => true, // 'mode' => 'single', From 026ee087dba174d7216cdec50a5d36110954af3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 26 Aug 2022 18:48:07 +0200 Subject: [PATCH 3/3] fix iterable types --- phpstan.neon.dist | 2 -- src/Chart.php | 28 +++++++++++++++++++++++----- src/PieChart.php | 25 ++----------------------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 90a63b9..0b95129 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,8 +9,6 @@ parameters: - vendor/ ignoreErrors: - - '~^(Property .+ has|Method .+\(\) (has parameter \$.+ with|return type has)) no value type specified in iterable type .+\.~' - # relax strict rules - '~^Only booleans are allowed in .+, .+ given( on the (left|right) side)?\.~' diff --git a/src/Chart.php b/src/Chart.php index c8e3ee8..e295217 100644 --- a/src/Chart.php +++ b/src/Chart.php @@ -20,7 +20,7 @@ class Chart extends View /** @var bool should we add JS include into application body? Set "false" if you do it manually. */ public $jsInclude = true; - /** @var array We will use these colors in charts */ + /** @var array We will use these colors in charts */ public $niceColors = [ ['rgba(255, 99, 132, 0.2)', 'rgba(255,99,132,1)'], ['rgba(54, 162, 235, 0.2)', 'rgba(54, 162, 235, 1)'], @@ -30,13 +30,13 @@ class Chart extends View ['rgba(255, 159, 64, 0.2)', 'rgba(255, 159, 64, 1)'], ]; - /** @var array Options for chart.js widget */ + /** @var array Options for chart.js widget */ public $options = []; - /** @var array Labels for axis. Fills with setModel(). */ + /** @var array Labels for axis. Fills with setModel(). */ protected $labels; - /** @var array Datasets. Fills with setModel(). */ + /** @var array> Datasets. Fills with setModel(). */ protected $datasets; protected function init(): void @@ -55,6 +55,9 @@ public function renderView(): void parent::renderView(); } + /** + * @return array + */ public function getConfig(): array { return [ @@ -67,22 +70,33 @@ public function getConfig(): array ]; } + /** + * @return array + */ public function getLabels(): array { return $this->labels; } + /** + * @return array> + */ public function getDatasets(): array { return array_values($this->datasets); } + /** + * @return array + */ public function getOptions(): array { return $this->options; } /** + * @param array $options + * * @return $this */ public function setOptions(array $options) @@ -100,10 +114,12 @@ public function setOptions(array $options) * * This component will automatically figure out name of the chart, * series titles based on column captions etc. + * + * @param array $columns */ public function setModel(Model $model, array $columns = []): void { - if (!$columns) { + if ($columns === []) { throw new Exception('Second argument must be specified to Chart::setModel()'); } @@ -210,6 +226,8 @@ public function withCurrencyY(string $char = '€') * ], * ])->withCurrency('$'); * + * @param array $options + * * @return $this */ public function summarize(Model $model, array $options = []) diff --git a/src/PieChart.php b/src/PieChart.php index dd51429..e99374c 100644 --- a/src/PieChart.php +++ b/src/PieChart.php @@ -13,17 +13,9 @@ class PieChart extends Chart /** @var string Type of chart */ public $type = 'pie'; - /** - * Specify data source for this chart. The column must contain - * the textual column first followed by sumber of data columns: - * setModel($month_report, ['month', 'total_sales', 'total_purchases']);. - * - * This component will automatically figure out name of the chart, - * series titles based on column captions etc. - */ public function setModel(Model $model, array $columns = []): void { - if (!$columns) { + if ($columns === []) { throw new Exception('Second argument must be specified to Chart::setModel()'); } @@ -41,11 +33,8 @@ public function setModel(Model $model, array $columns = []): void } $this->datasets[$column] = [ - // 'label' => $model->getField($column)->getCaption(), 'data' => [], - 'backgroundColor' => [], // $colors[0], - // 'borderColor' => [], // $colors[1], - // 'borderWidth' => 1, + 'backgroundColor' => [], ]; } @@ -61,20 +50,10 @@ public function setModel(Model $model, array $columns = []): void } } - /** - * Add currency label. - * - * @param string $char Currency symbol - * @param string $axis y or x - * - * @return $this - */ public function withCurrency(string $char = '€', string $axis = 'y') { $options = []; $options['tooltips'] = [ - // 'enabled' => true, - // 'mode' => 'single', 'callbacks' => [ 'label' => new JsExpression('{}', [ 'function(item, data, bb) {