Skip to content

Commit

Permalink
Merge pull request #44 from CottaCush/fixes/check-deprecation
Browse files Browse the repository at this point in the history
fix issue with deprecation
  • Loading branch information
beccadaniel authored Feb 22, 2021
2 parents b8afdeb + a2fb5db commit 25865fd
Show file tree
Hide file tree
Showing 32 changed files with 1,552 additions and 276 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ before_script:
- travis_retry composer require php-coveralls/php-coveralls:~2.0

script:
- vendor/bin/phpcs --standard=psr2 src/
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpcs --standard=psr2 src -n
- vendor/bin/phpunit --coverage-text --coverage-clover=.build/logs/clover.xml

after_success:
- sh -c 'php vendor/bin/coveralls -v'
19 changes: 10 additions & 9 deletions src/Action/BaseAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
use CottaCush\Yii2\Controller\BaseController;
use yii\base\Action;
use yii\db\ActiveRecord;
use yii\web\ForbiddenHttpException;
use yii\web\Response;

class BaseAction extends Action
{
/** @var ActiveRecord $model */
public $model;
public ActiveRecord $model;

public $postData;
public $returnUrl = '';
public string $returnUrl = '';

public $recordNotFound = 'Record not found';
public $errorMessage = '';
public $successMessage = '';
public string $recordNotFound = 'Record not found';
public string $errorMessage = '';
public string $successMessage = '';

/** @var bool Checks if the login is required before action is executed */
public $requireLogin = true;
public bool $requireLogin = true;

/**
* @return bool|Response
* @throws ForbiddenHttpException
* @author Olawale Lawal <[email protected]>
* @return bool|\yii\web\Response
*/
public function beforeRun()
public function beforeRun(): Response|bool
{
if (!$this->requireLogin) {
return true;
Expand Down
9 changes: 6 additions & 3 deletions src/Action/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace CottaCush\Yii2\Action;

use CottaCush\Yii2\Controller\BaseController;
use yii\base\ExitException;
use yii\web\Response;

/**
* Class DeleteAction
Expand All @@ -17,17 +19,18 @@ class DeleteAction extends BaseAction
{
public $deleteAttribute = 'is_active';
public $deleteStatus = 0;
public $errorMessage = 'Record not found';
public string $errorMessage = 'Record not found';

public $extraFields = null;
public $formName = '';

/**
* @return Response
* @throws ExitException
* @author Adegoke Obasa <[email protected]>
* @author Akinwunmi Taiwo <[email protected]>
* @return \yii\web\Response
*/
public function run()
public function run(): Response
{
/** @var BaseController $controller */
$controller = $this->controller;
Expand Down
12 changes: 8 additions & 4 deletions src/Action/SaveAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

use CottaCush\Yii2\Controller\BaseController;
use CottaCush\Yii2\Model\BaseModel;
use Yii;
use yii\base\ExitException;
use yii\helpers\Json;
use yii\web\Response;
use yii\widgets\ActiveForm;

/**
Expand All @@ -20,11 +23,12 @@ class SaveAction extends BaseAction
public $enableAjaxValidation = false;

/**
* @author Adegoke Obasa <[email protected]>
* @return string|Response
* @throws ExitException
* @author Akinwunmi Taiwo <[email protected]>
* @return \yii\web\Response
* @author Adegoke Obasa <[email protected]>
*/
public function run()
public function run(): Response|string
{
/** @var BaseController $controller */
$controller = $this->controller;
Expand All @@ -40,7 +44,7 @@ public function run()
$model = new $this->model;
$model->load($this->postData);

if (\Yii::$app->request->isAjax && $this->enableAjaxValidation) {
if (Yii::$app->request->isAjax && $this->enableAjaxValidation) {
return Json::encode(ActiveForm::validate($model));
}

Expand Down
7 changes: 5 additions & 2 deletions src/Action/SoftDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use CottaCush\Yii2\Constants\Messages;
use CottaCush\Yii2\Controller\BaseController;
use CottaCush\Yii2\Model\BaseModel;
use yii\base\ExitException;
use yii\db\IntegrityException;
use yii\web\Response;

class SoftDeleteAction extends DeleteAction
{
Expand All @@ -17,10 +19,11 @@ class SoftDeleteAction extends DeleteAction
public $integrityViolationMessage = Messages::RECORD_USED_ALREADY;

/**
* @return Response
* @throws ExitException
* @author Olawale Lawal <[email protected]>
* @return \yii\web\Response
*/
public function run()
public function run(): Response
{
/** @var BaseController $controller */
$controller = $this->controller;
Expand Down
7 changes: 5 additions & 2 deletions src/Action/UpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
namespace CottaCush\Yii2\Action;

use CottaCush\Yii2\Controller\BaseController;
use yii\base\ExitException;
use yii\db\IntegrityException;
use yii\web\Response;

/**
* Class UpdateAction
Expand All @@ -19,11 +21,12 @@ class UpdateAction extends BaseAction
public $integrityExceptionMessage = 'Record cannot be updated as it is in use elsewhere';

/**
* @return Response
* @throws ExitException
* @author Adegoke Obasa <[email protected]>
* @author Akinwunmi Taiwo <[email protected]>
* @return \yii\web\Response
*/
public function run()
public function run(): Response
{
/** @var BaseController $controller */
$controller = $this->controller;
Expand Down
13 changes: 9 additions & 4 deletions src/Constants/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Messages
* @param string $task
* @return string
*/
public static function getSuccessMessage($entity, $task = self::TASK_CREATE)
public static function getSuccessMessage($entity, $task = self::TASK_CREATE): string
{
return sprintf('%s %s successfully', $entity, $task);
}
Expand All @@ -35,7 +35,7 @@ public static function getSuccessMessage($entity, $task = self::TASK_CREATE)
* @param string $creationTask
* @return string
*/
public static function getEmptyStateMessage($entity, $creationTask = self::TASK_CREATE)
public static function getEmptyStateMessage($entity, $creationTask = self::TASK_CREATE): string
{
return sprintf('No %s has been %s', $entity, $creationTask);
}
Expand All @@ -46,12 +46,17 @@ public static function getEmptyStateMessage($entity, $creationTask = self::TASK_
* @param string $action
* @return string
*/
public static function getWarningMessage($entity, $action)
public static function getWarningMessage($entity, $action): string
{
return sprintf('Are you sure you want to %s this %s?', $action, $entity);
}

public static function getIntegrityViolationMsg($entity, $task = self::TASK_DELETE)
/**
* @param $entity
* @param string $task
* @return string
*/
public static function getIntegrityViolationMsg($entity, $task = self::TASK_DELETE): string
{
return sprintf('This %s is in use, hence cannot be %s', $entity, $task);
}
Expand Down
32 changes: 19 additions & 13 deletions src/Controller/BaseConsoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace CottaCush\Yii2\Controller;

use Yii;
use yii\base\Action;
use yii\console\Controller;
use yii\db\Connection;
use yii\db\Exception;
use yii\db\Query;
use yii\db\Transaction;

Expand All @@ -23,14 +26,14 @@ class BaseConsoleController extends Controller
protected $transaction;

/**
* @author Olawale Lawal <[email protected]>
* @param \yii\base\Action $action
* @param Action $action
* @return bool
* @author Olawale Lawal <[email protected]>
*/
public function beforeAction($action)
public function beforeAction(Action $action): bool
{
if (is_null($this->db)) {
$this->db = \Yii::$app->db;
$this->db = Yii::$app->db;
}
return parent::beforeAction($action);
}
Expand All @@ -44,6 +47,7 @@ public function beginTransaction()
}

/**
* @throws Exception
* @author Olawale Lawal <[email protected]>
*/
public function commitTransaction()
Expand All @@ -67,44 +71,46 @@ public function rollbackTransaction()
* @param string $returnColumn
* @return false|null|string
*/
public static function getColumnByField($table, $field, $value, $returnColumn = 'id')
public static function getColumnByField($table, $field, $value, $returnColumn = 'id'): bool|string|null
{
return (new Query)->select($returnColumn)
->from($table)->filterWhere([$field => $value])
->scalar();
}

public function getRandomOne($table, $column, $conditions = [])
public function getRandomOne($table, $column, $conditions = []): bool|array
{
return (new Query)->select($column)
->from($table)->filterWhere($conditions)->orderBy('rand()')->one();
}

public function getAll($table, $columns, $conditions = [])
public function getAll($table, $columns, $conditions = []): array
{
return (new Query)->select($columns)
->from($table)->andFilterWhere($conditions)->all();
}

/**
* @author Olawale Lawal <[email protected]>
* @param $table
* @param array $columns
* @return int
* @throws Exception
* @author Olawale Lawal <[email protected]>
*/
public function insert($table, array $columns)
public function insert($table, array $columns): int
{
return $this->db->createCommand()->insert($table, $columns)->execute();
}

/**
* @author Olawale Lawal <[email protected]>
* @param $table
* @param array $columns
* @param array $rows
* @return int
* @return bool|int
* @throws Exception
* @author Olawale Lawal <[email protected]>
*/
public function batchInsert($table, array $columns, array $rows)
public function batchInsert($table, array $columns, array $rows): bool|int
{
if (empty($rows)) {
return true;
Expand All @@ -113,7 +119,7 @@ public function batchInsert($table, array $columns, array $rows)
return $this->db->createCommand()->batchInsert($table, $columns, $rows)->execute();
}

public function stdout($string)
public function stdout($string): void
{
parent::stdout($string . PHP_EOL);
}
Expand Down
Loading

0 comments on commit 25865fd

Please sign in to comment.