Skip to content

Commit

Permalink
add phpstan (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar authored Jul 21, 2022
1 parent 5628804 commit 1a07d86
Show file tree
Hide file tree
Showing 35 changed files with 98 additions and 23 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ env:
CC_TEST_REPORTER_ID: c8387c181b15919319ac86be13d5e5022ec09aed1b8460572a793431080a52e3
jobs:

## PHPSTAN
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@2.21.0
with:
php-version: '8.0'
extensions: mbstring, intl
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: PHPStan tests
run: composer phpstan

## PHP UNIT
phpunit:
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
Expand Down
3 changes: 2 additions & 1 deletion src/apis/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,15 @@ public function actionGetFilemanagerFolderState()
* Store the open and closed folders from the filemanager tree in the user settings.
*
* @uses array data
* @return boolean
*/
public function actionFilemanagerFoldertreeHistory()
{
$this->deleteHasCache('storageApiDataFolders');

$data = Yii::$app->request->getBodyParam('data');
Yii::$app->adminuser->identity->setting->set('foldertree.'.$data['id'], (int) $data['toggle_open']);

return Yii::$app->response->statusCode = 204;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/aws/FlowActiveWindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ public function callbackRemove($imageId)

/**
* Flow Uploader Upload.
*
* @return string
*/
public function callbackUpload()
{
Expand Down
8 changes: 8 additions & 0 deletions src/base/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ abstract public function label();
*/
abstract public function type();

/**
* {@inheritDoc}
*/
final public function __construct($config = [])
{
parent::__construct($config);
}

/**
* When the object is force to return as string the `getValue()` method is returned.
*
Expand Down
2 changes: 0 additions & 2 deletions src/commands/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class FilterController extends Command

/**
* Create a new image filter to apply on an Image Object.
*
* @return number
*/
public function actionIndex()
{
Expand Down
2 changes: 0 additions & 2 deletions src/components/UrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace luya\admin\components;

use yii;

/**
* Url rule for NgRest Apis.
*
Expand Down
4 changes: 3 additions & 1 deletion src/models/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function getTypeBadge()
case self::TYPE_SUCCESS:
return '<span class="badge badge-success">success</span>';
}

return '';
}

public function ngRestGroupByField()
Expand All @@ -177,7 +179,7 @@ public function extraFields()
public function ngRestConfig($config)
{
$config->aw->load([
'class' => DetailViewActiveWindow::className(),
'class' => DetailViewActiveWindow::class,
'attributes' => [
'id',
'time:datetime',
Expand Down
2 changes: 2 additions & 0 deletions src/models/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ private function userAttemptBruteForceLock(User $user)
}

$user->updateAttributes(['login_attempt' => $this->attempts]);

return false;
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/models/StorageFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function rules()
* Override default implementation. Mark as deleted and remove files from file system.
*
* Keep file in order to provide all file references.
*
* @return boolean
*
* @return int|boolean
*/
public function delete()
{
Expand All @@ -135,6 +135,8 @@ public function delete()
$this->afterDelete();
return true;
}

return false;
}

/**
Expand Down Expand Up @@ -269,7 +271,7 @@ public function getIsImage()
*
* > This method is used internal when uploading a file which is an image, the file manager preview images are created here.
*
* @return array Returns an array with the key source which contains the source to the thumbnail.
* @return array|boolean Returns an array with the key source which contains the source to the thumbnail.
* @since 1.2.2.1
*/
public function getCreateThumbnail()
Expand All @@ -290,14 +292,16 @@ public function getCreateThumbnail()
if ($image) {
return ['source' => $image->source];
}

return false;
}

/**
* Create the thumbnail medium for this given file if its an image.
*
* > This method is used internal when uploading a file which is an image, the file manager preview images are created here.
*
* @return array Returns an array with the key source which contains the source to the thumbnail medium.
* @return array|boolean Returns an array with the key source which contains the source to the thumbnail medium.
* @since 1.2.2.1
*/
public function getCreateThumbnailMedium()
Expand All @@ -318,6 +322,8 @@ public function getCreateThumbnailMedium()
if ($image) {
return ['source' => $image->source];
}

return false;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/models/StorageFilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public function applyFilter(ImageInterface $image, array $saveOptions)
$image = Image::text($image, $this->effectChainValue($imagineEffectName, 'text'), $this->effectChainValue($imagineEffectName, 'fontFile'), $this->effectChainValue($imagineEffectName, 'start'));
return [$image, $saveOptions];
}

throw new InvalidConfigException("Missing effect.");
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/models/UserChangePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public function attributeLabels()

/**
* Checks if the password is valid and stores the new password.
*
* @return boolean
*/
public function checkAndStore()
{
Expand Down
6 changes: 2 additions & 4 deletions src/ngrest/base/NgRestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ abstract class NgRestModel extends ActiveRecord implements GenericSearchInterfac
protected $ngRestServiceArray = [];

/**
* Attach behaviors at constructor to prevent override them with call of behaviors() at subclass model.
*
* @param array $config
* {@inheritDoc}
*/
public function __construct($config = [])
{
Expand All @@ -86,7 +84,7 @@ public function __construct($config = [])
'api' => static::ngRestApiEndpoint(),
],
]);
return parent::__construct($config);
parent::__construct($config);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/ngrest/base/NgRestModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface NgRestModelInterface extends ActiveRecordInterface
* Defines the base inline configuration for the current Model.
*
* @param \luya\admin\ngrest\ConfigBuilder $config ConfigBuilder Object
* @return \luya\admin\ngrest\ConfigBuilder
*/
public function ngRestConfig($config);

Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,7 @@ public function onAfterListFind($event)
}
$this->writeAttribute($event, implode(", ", $results));
}

return true;
}
}
4 changes: 4 additions & 0 deletions src/ngrest/plugins/CheckboxRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public function onBeforeExpandFind($event)
$data[] = ['value' => $item[$this->getModelPrimaryKey()]];
}
$event->sender->{$this->name} = $data;

return true;
}

/**
Expand All @@ -262,6 +264,8 @@ public function onBeforeFind($event)
if (!$this->onlyRestScenarios) {
$event->sender->{$this->name} = $this->getRelationData($event);
}

return true;
}

private function getRelationData($event)
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/CmsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ public function onAfterFind($event)

// assign value
$this->writeAttribute($event, $menuItem);

return true;
}
}
4 changes: 4 additions & 0 deletions src/ngrest/plugins/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function onAfterExpandFind($event)
} else {
$this->writeAttribute($event, (float) $fieldValue);
}

return true;
}

/**
Expand All @@ -63,5 +65,7 @@ public function onAfterExpandFind($event)
public function onAfterFind($event)
{
$this->writeAttribute($event, (float) $event->sender->getAttribute($this->name));

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ public function onAfterFind($event)
if ($this->fileItem) {
$this->writeAttribute($event, Yii::$app->storage->getFile($this->getAttributeValue($event)));
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/FileArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function onAfterFind($event)
if ($this->fileIterator) {
$this->writeAttribute($event, $this->parseFileIteration($event->sender->getAttribute($this->name)));
}

return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ public function onAfterFind($event)
if ($this->nl2br) {
$this->writeAttribute($event, nl2br($event->sender->getAttribute($this->name)));
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function onAfterFind($event)
if ($this->imageItem) {
$this->writeAttribute($event, Yii::$app->storage->getImage($event->sender->getAttribute($this->name)));
}

return true;
}

public function serviceData($event)
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/ImageArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public function onAfterFind($event)
if ($this->imageIterator) {
$this->writeAttribute($event, $this->parseImageIteration($event->sender->getAttribute($this->name)));
}

return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/JsonObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ public function onBeforeExpandFind($event)
public function onAfterFind($event)
{
$this->writeAttribute($event, Json::decode($event->sender->getAttribute($this->name)));

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public function onBeforeFind($event)
public function onAfterFind($event)
{
$this->writeAttribute($event, $this->generateLinkObject($event->sender->getAttribute($this->name)));

return true;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/ngrest/plugins/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function onAfterExpandFind($event)
} else {
$this->writeAttribute($event, (int) $fieldValue);
}

return true;
}

/**
Expand All @@ -76,5 +78,7 @@ public function onAfterExpandFind($event)
public function onAfterFind($event)
{
$this->writeAttribute($event, (int) $event->sender->getAttribute($this->name));

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@ public function onAfterListFind($event)
}
}
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/SelectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public function onAfterListFind($event)
if ($this->modelClass !== $event->sender->className()) {
return parent::onAfterListFind($event);
}

return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/SortRelationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ public function onAfterFind($event)
$class = $this->modelClass;
$this->writeAttribute($event, $class::ngRestFind()->where(['in', 'id', $ids])->all());
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/ngrest/plugins/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function onAfterFind($event)
if ($this->encoding) {
$this->writeAttribute($event, HtmlHelper::encode($event->sender->getAttribute($this->name)));
}

return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/TextArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function onBeforeFind($event)
public function onAfterFind($event)
{
$this->writeAttribute($event, $this->transformList($event->sender->getAttribute($this->name)));

return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ngrest/plugins/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function onAfterFind($event)
if ($this->markdown) {
$this->writeAttribute($event, TagParser::convertWithMarkdown($event->sender->getAttribute($this->name)));
}

return true;
}

/**
Expand Down
Loading

0 comments on commit 1a07d86

Please sign in to comment.