Skip to content

Commit 583a4a8

Browse files
authored
Upgrade phpstan to v1.0 (#1686)
1 parent c7e1960 commit 583a4a8

20 files changed

+495
-563
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"instaclick/php-webdriver": "^1.4.7",
7373
"johnkary/phpunit-speedtrap": "^3.3",
7474
"phpstan/extension-installer": "^1.1",
75-
"phpstan/phpstan": "^0.12.82",
75+
"phpstan/phpstan": "^1.0",
7676
"phpunit/phpunit": "^9.5.5",
7777
"symfony/console": "^4.4.30 || ^5.3.7",
7878
"symfony/css-selector": "^4.4.24 || ^5.2.9",

demos/_includes/Counter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class Counter extends \Atk4\Ui\Form\Control\Line
1111
{
12-
public $content = 20; // default
12+
public $content = '20'; // default
1313

1414
protected function init(): void
1515
{

phpstan.neon.dist

+459-509
Large diffs are not rendered by default.

src/App.php

+2-15
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ class App
127127
/** @var View[] Modal view that need to be rendered using json output. */
128128
private $portals = [];
129129

130-
/**
131-
* @var bool whether or not semantic-ui vue has been initialised
132-
*/
133-
private $is_sui_init = false;
134-
135130
/**
136131
* @var string used in method App::url to build the url
137132
*
@@ -227,7 +222,7 @@ static function (int $severity, string $msg, string $file, int $line): bool {
227222
}
228223

229224
// Set up UI persistence
230-
if (!isset($this->ui_persistence)) {
225+
if ($this->ui_persistence === null) {
231226
$this->ui_persistence = new UiPersistence();
232227
}
233228

@@ -484,7 +479,7 @@ public function initLayout($seed)
484479
$layout = Layout::fromSeed($seed);
485480
$layout->setApp($this);
486481

487-
if (!$this->html) {
482+
if ($this->html === null) {
488483
$this->html = new View(['defaultTemplate' => 'html.html']);
489484
$this->html->setApp($this);
490485
$this->html->invokeInit();
@@ -535,9 +530,6 @@ public function initIncludes()
535530
*/
536531
public function addStyle($style)
537532
{
538-
if (!$this->html) {
539-
throw new Exception('App does not know how to add style');
540-
}
541533
$this->html->template->dangerouslyAppendHtml('HEAD', $this->getTag('style', $style));
542534
}
543535

@@ -568,11 +560,6 @@ public function run()
568560
$this->hook(self::HOOK_BEFORE_RENDER);
569561
$this->is_rendering = true;
570562

571-
// if no App layout set
572-
if (!isset($this->html)) {
573-
throw new Exception('App layout should be set.');
574-
}
575-
576563
$this->html->template->set('title', $this->title);
577564
$this->html->renderAll();
578565
$this->html->template->dangerouslyAppendHtml('HEAD', $this->html->getJs());

src/Form/AbstractLayout.php

-7
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,9 @@ public function setModel(\Atk4\Data\Model $model, $fields = null)
163163
/**
164164
* Return Field decorator associated with
165165
* the form's field.
166-
*
167-
* @return \Atk4\Ui\Form\Control
168166
*/
169167
public function getControl(string $name): Control
170168
{
171-
if (empty($this->form)) {
172-
throw (new Exception('Incorrect value for $form'))
173-
->addMoreInfo('form', $this->form);
174-
}
175-
176169
return $this->form->getControl($name);
177170
}
178171

src/Form/Control/Dropdown.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function getInput()
177177
*/
178178
public function getValue()
179179
{
180-
return isset($this->field)
180+
return $this->field !== null
181181
? (is_array($this->field->get()) ? implode(',', $this->field->get()) : $this->field->get())
182182
: parent::getValue();
183183
}
@@ -247,7 +247,7 @@ protected function htmlRenderValue(): void
247247
}
248248

249249
// model set? use this, else values property
250-
if (isset($this->model)) {
250+
if ($this->model !== null) {
251251
if ($this->renderRowFunction) {
252252
foreach ($this->model as $row) {
253253
$this->_addCallBackRow($row);

src/Form/Control/Input.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function setInputAttr($attr, $value = null)
9797
*/
9898
public function getValue()
9999
{
100-
return isset($this->field)
100+
return $this->field !== null
101101
? $this->getApp()->ui_persistence->typecastSaveField($this->field, $this->field->get())
102102
: ($this->content ?? '');
103103
}

src/Form/Control/Lookup.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Lookup extends Input
6868
* true = will use "Add new" label
6969
* string = will use your string
7070
*
71-
* @var bool|string|null
71+
* @var bool|string|array|null
7272
*/
7373
public $plus = false;
7474

@@ -249,17 +249,22 @@ protected function initQuickNewRecord()
249249
return;
250250
}
251251

252-
$this->plus = is_bool($this->plus) ? 'Add New' : $this->plus;
252+
if ($this->plus === true) {
253+
$this->plus = 'Add New';
254+
}
253255

254-
$this->plus = is_string($this->plus) ? ['button' => $this->plus] : $this->plus;
256+
if (is_string($this->plus)) {
257+
$this->plus = ['button' => $this->plus];
258+
}
255259

256260
$buttonSeed = $this->plus['button'] ?? [];
257-
258-
$buttonSeed = is_string($buttonSeed) ? ['content' => $buttonSeed] : $buttonSeed;
261+
if (is_string($buttonSeed)) {
262+
$buttonSeed = ['content' => $buttonSeed];
263+
}
259264

260265
$defaultSeed = [\Atk4\Ui\Button::class, 'disabled' => ($this->disabled || $this->readonly)];
261266

262-
$this->action = Factory::factory(array_merge($defaultSeed, (array) $buttonSeed));
267+
$this->action = Factory::factory(array_merge($defaultSeed, $buttonSeed));
263268

264269
if ($this->form) {
265270
$vp = \Atk4\Ui\VirtualPage::addTo($this->form);

src/Form/Control/ScopeBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ protected function renderView(): void
554554
'maxDepth' => $this->maxDepth,
555555
'query' => $this->query,
556556
'name' => $this->short_name,
557-
'labels' => $this->labels ?? null,
557+
'labels' => $this->labels ?: null,
558558
'form' => $this->form->formElement->name,
559559
'debug' => $this->options['debug'] ?? false,
560560
],

src/Form/Control/Upload.php

-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ class Upload extends Input
8484
public const UPLOAD_ACTION = 'upload';
8585
public const DELETE_ACTION = 'delete';
8686

87-
/** @var bool check if callback is trigger by one of the action. */
88-
private $_isCbRunning = false;
89-
9087
protected function init(): void
9188
{
9289
parent::init();

src/Grid.php

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class Grid extends View
1818
{
1919
use HookTrait;
2020

21-
/** @const string not used, make it public if needed or drop it */
22-
private const HOOK_ON_USER_ACTION = self::class . '@onUserAction';
23-
2421
/**
2522
* Will be initialized to Menu object, however you can set this to false to disable menu.
2623
*

src/Lister.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function renderView(): void
169169
// empty message
170170
if (!$this->_rendered_rows_count) {
171171
if (!$this->jsPaginator || !$this->jsPaginator->getPage()) {
172-
$empty = isset($this->t_empty) ? $this->t_empty->renderToHtml() : '';
172+
$empty = $this->t_empty !== null ? $this->t_empty->renderToHtml() : '';
173173
if ($this->template->hasTag('rows')) {
174174
$this->template->dangerouslyAppendHtml('rows', $empty);
175175
} else {

src/Persistence/Ui.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function _typecastSaveField(\Atk4\Data\Field $field, $value): string
7171
$format = $field->persist_format ?: $formats[$field->type];
7272

7373
// datetime only - set to persisting timezone
74-
if ($field->type === 'datetime' && isset($field->persist_timezone)) {
74+
if ($field->type === 'datetime') {
7575
$value = new \DateTime($value->format('Y-m-d H:i:s.u'), $value->getTimezone());
7676
$value->setTimezone(new \DateTimeZone($field->persist_timezone));
7777
}
@@ -111,7 +111,7 @@ protected function _typecastLoadField(\Atk4\Data\Field $field, $value)
111111

112112
// datetime only - set from persisting timezone
113113
$valueStr = is_object($value) ? $this->_typecastSaveField($field, $value) : $value;
114-
if ($field->type === 'datetime' && isset($field->persist_timezone)) {
114+
if ($field->type === 'datetime') {
115115
$value = $dt_class::createFromFormat($format, $valueStr, new $tz_class($field->persist_timezone));
116116
if ($value === false) {
117117
throw (new Exception('Incorrectly formatted datetime'))

src/Table/Column/Labels.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class Labels extends Table\Column
2020
{
21-
/** @var array Array of allowed values. This have precedence over->values */
21+
/** @var array|null Array of allowed values. This have precedence over->values */
2222
public $values;
2323

2424
/**

src/UserAction/ExecutorFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ protected function getAddMenuItem(UserAction $action): array
255255
*/
256256
protected function getAddActionCaption(UserAction $action): string
257257
{
258-
return 'Add ' . $action->getModel()->caption ?? '';
258+
return 'Add' . ($action->getModel()->caption ? ' ' . $action->getModel()->caption : '');
259259
}
260260

261261
// Generate id for a model user action.

src/UserAction/PanelExecutor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PanelExecutor extends Right implements JsExecutorInterface
2929
public $dynamic = [];
3030
public $hasClickAway = false;
3131

32-
/** @var string */
32+
/** @var string|null */
3333
public $title;
3434

3535
/** @var Header */

src/UserAction/VpExecutor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class VpExecutor extends View implements JsExecutorInterface
2929
/** @var VirtualPage */
3030
protected $vp;
3131

32-
/** @var string */
32+
/** @var string|null */
3333
public $title;
3434

3535
/** @var Header */

src/View.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*/
1515
class View extends AbstractView implements JsExpressionable
1616
{
17-
// {{{ Properties of the class
18-
1917
/**
2018
* When you call render() this will be populated with JavaScript
2119
* chains.
@@ -102,7 +100,7 @@ class View extends AbstractView implements JsExpressionable
102100
/**
103101
* Set static contents of this view.
104102
*
105-
* @var string|false
103+
* @var string|false|null
106104
*/
107105
public $content;
108106

@@ -113,9 +111,8 @@ class View extends AbstractView implements JsExpressionable
113111
*/
114112
public $element;
115113

116-
/** @var ExecutorFactory Seed class name */
117-
public $executorFactory;
118-
// }}}
114+
/** @var ExecutorFactory|null Seed class name */
115+
protected $executorFactory;
119116

120117
// {{{ Setting Things up
121118

@@ -711,7 +708,7 @@ protected function recursiveRender(): void
711708
}
712709
}
713710

714-
if (isset($this->content) && $this->content !== false) {
711+
if ($this->content !== null && $this->content !== false) {
715712
$this->template->append('Content', $this->content);
716713
}
717714
}

tests/CallbackTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Atk4\Ui\AbstractView;
99
use Atk4\Ui\Callback;
1010
use Atk4\Ui\VirtualPage;
11+
use Mvorisek\Atk4\Hintable\Phpstan\PhpstanUtil;
1112

1213
class AppMock extends \Atk4\Ui\App
1314
{
@@ -17,6 +18,8 @@ class AppMock extends \Atk4\Ui\App
1718
public function terminate($output = '', array $headers = []): void
1819
{
1920
$this->terminated = true;
21+
22+
PhpstanUtil::fakeNeverReturn();
2023
}
2124

2225
/**

tests/FormTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Atk4\Ui\App;
1010
use Atk4\Ui\Callback;
1111
use Atk4\Ui\Form;
12+
use Mvorisek\Atk4\Hintable\Phpstan\PhpstanUtil;
1213

1314
class FormTest extends TestCase
1415
{
@@ -183,5 +184,7 @@ class AppFormTestMock extends App
183184
public function terminate($output = '', array $headers = []): void
184185
{
185186
$this->output = $output;
187+
188+
PhpstanUtil::fakeNeverReturn();
186189
}
187190
}

0 commit comments

Comments
 (0)