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

Enable phpstan bleading edge and strict rules #21

Merged
merged 3 commits into from
Aug 27, 2022
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
15 changes: 15 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 1 addition & 8 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

$finder = PhpCsFixer\Finder::create()
->in([__DIR__])
->exclude([
'cache',
'build',
'vendor',
]);
->exclude(['vendor']);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions codecov.yml

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 5 additions & 18 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
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\(\)\.$~'
# 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\(\)\.$~'
29 changes: 24 additions & 5 deletions src/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, array{string, string}> 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)'],
Expand All @@ -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<string, mixed> Options for chart.js widget */
public $options = [];

/** @var array Labels for axis. Fills with setModel(). */
/** @var array<int, string> Labels for axis. Fills with setModel(). */
protected $labels;

/** @var array Datasets. Fills with setModel(). */
/** @var array<string, array<string, mixed>> Datasets. Fills with setModel(). */
protected $datasets;

protected function init(): void
Expand All @@ -55,6 +55,9 @@ public function renderView(): void
parent::renderView();
}

/**
* @return array<string, mixed>
*/
public function getConfig(): array
{
return [
Expand All @@ -67,22 +70,33 @@ public function getConfig(): array
];
}

/**
* @return array<int, string>
*/
public function getLabels(): array
{
return $this->labels;
}

/**
* @return array<int, array<string, mixed>>
*/
public function getDatasets(): array
{
return array_values($this->datasets);
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}

/**
* @param array<string, mixed> $options
*
* @return $this
*/
public function setOptions(array $options)
Expand All @@ -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<int, string> $columns
*/
public function setModel(Model $model, array $columns = []): void
{
if (!$columns) {
if ($columns === []) {
throw new Exception('Second argument must be specified to Chart::setModel()');
}

Expand Down Expand Up @@ -148,6 +164,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, ","); }']),
Expand Down Expand Up @@ -209,6 +226,8 @@ public function withCurrencyY(string $char = '€')
* ],
* ])->withCurrency('$');
*
* @param array<string, mixed> $options
*
* @return $this
*/
public function summarize(Model $model, array $options = [])
Expand Down
2 changes: 1 addition & 1 deletion src/ChartBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Atk4\Ui\View;

/**
* Implements a box that contains a chart.
* Box that contains a chart.
*/
class ChartBox extends View
{
Expand Down
26 changes: 3 additions & 23 deletions src/PieChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()');
}

Expand All @@ -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' => [],
];
}

Expand All @@ -61,19 +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) {
Expand Down