fix: phpstan. Удаление State

This commit is contained in:
origami11@yandex.ru 2024-01-24 12:49:11 +03:00
parent 4ac027b8ee
commit 1638d558c5
6 changed files with 22 additions and 97 deletions

View file

@ -6,14 +6,10 @@ use Exception,
ctiso\Url, ctiso\Url,
ctiso\Model\Factory, ctiso\Model\Factory,
ctiso\HttpRequest, ctiso\HttpRequest,
ctiso\Functions,
ctiso\Settings, ctiso\Settings,
ctiso\Registry,
ctiso\Role\User,
ctiso\View\Composite, ctiso\View\Composite,
ctiso\Filter\ActionAccess,
ctiso\View\View, ctiso\View\View,
ctiso\Controller\State; App\Controller\State;
/** /**
* Контроллер страниц * Контроллер страниц
*/ */

View file

@ -5,6 +5,7 @@
*/ */
namespace ctiso\Controller; namespace ctiso\Controller;
use ctiso\Path, use ctiso\Path,
ctiso\Model\BaseMapper,
ctiso\File, ctiso\File,
ctiso\Registry, ctiso\Registry,
ctiso\Database\PDOStatement; ctiso\Database\PDOStatement;
@ -40,8 +41,8 @@ class Service
/** /**
* Создает модель * Создает модель
* @param string $name * @param string $name
* @return Model * @return BaseMapper
*/ */
public function getModel($name) public function getModel($name)
{ {

View file

@ -1,74 +0,0 @@
<?php
namespace ctiso\Controller;
use ctiso\Controller\Action,
ctiso\Url;
class State
{
public $action = '';
public $states = array();
public $titles = array();
public function __construct($action)
{
$this->action = $action;
}
static function make($action)
{
return new State($action);
}
public function addTitle($name, $url = array())
{
$this->titles [] = array($name, $url);
return $this;
}
public function addState(State $state)
{
$this->states [$state->getAction()] = $state;
return $this;
}
public function getAction()
{
return $this->action;
}
function checkAction($action, &$list)
{
if ($this->action == $action) {
array_push($list, $this);
return true;
} else {
foreach ($this->states as $state) {
if ($state->checkAction($action, $list)) {
array_push($list, $this);
return true;
}
}
}
return false;
}
function makeTitle(Action $module)
{
foreach ($this->titles as $item) {
$module->path->addMenuItem($module->nUrl($this->action, $item[1]), $item[0]);
}
}
function getPath($module, $action)
{
$list = array();
if ($this->checkAction($action, $list)) {
foreach (array_reverse($list) as $item) {
$item->makeTitle($module);
}
} else {
$this->makeTitle($module);
}
}
}

View file

@ -51,7 +51,7 @@ class Database/*<Database_PDOStatement>*/ extends PDO
$connection = null; $connection = null;
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') { if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; $port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
$connection/*: Database*/ = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); $connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
if ($dsn['phptype'] == 'pgsql') { if ($dsn['phptype'] == 'pgsql') {
$connection->query('SET client_encoding="UTF-8"'); $connection->query('SET client_encoding="UTF-8"');
} }
@ -61,7 +61,7 @@ class Database/*<Database_PDOStatement>*/ extends PDO
} }
} }
if ($dsn['phptype'] == 'sqlite') { if ($dsn['phptype'] == 'sqlite') {
$connection/*: Database*/ = new static("{$dsn['phptype']}:{$dsn['database']}"); $connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}");
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5); $connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL'; $mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
$connection->query("PRAGMA journal_mode=$mode"); $connection->query("PRAGMA journal_mode=$mode");

View file

@ -21,10 +21,10 @@ class Field
public $_title = array(); public $_title = array();
public $description = ""; public $description = "";
public $alias = array(); public $alias = array();
/** @phpstan-ignore-next-line */
public function __construct ($input = array(), $factory = null) public function __construct ($input = array(), $factory = null)
{ {
$this->default = null; $this->default = null;
if (isset($input['validate'])) { if (isset($input['validate'])) {
$this->require = strpos($input['validate'], 'require') !== false; $this->require = strpos($input['validate'], 'require') !== false;

View file

@ -47,21 +47,23 @@ class Primitive {
{ {
$result = 0; $result = 0;
$tmp = explode("/", $value ?? '', 3); $tmp = explode("/", $value ?? '', 3);
if (!empty($tmp)) {
if (count($tmp) != 3) return $result; if (count($tmp) != 3) {
return $result;
}
$year = (int)$tmp[2]; $year = (int)$tmp[2];
$month = (int)$tmp[1]; $month = (int)$tmp[1];
$day = (int)$tmp[0]; $day = (int)$tmp[0];
if ($month != 0 && $day != 0 && $year != 0) { if ($month != 0 && $day != 0 && $year != 0) {
if (checkdate($month, $day, $year)) { if (checkdate($month, $day, $year)) {
return mktime(0, 0, 0, $month, $day, $year); return mktime(0, 0, 0, $month, $day, $year);
} else { } else {
return 0; return 0;
}
} }
} }
return $result; return $result;
} }