File Nav.php
has 595 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace luya\cms\models;
use luya\admin\models\Group;
Nav
has 34 functions (exceeds 20 allowed). Consider refactoring. Open
class Nav extends ActiveRecord
{
use TaggableTrait;
/**
Method createPageFromDraft
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false): bool|array
{
if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) {
$isDraft = 0;
}
Method createPage
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false): array|int
{
$_errors = [];
$nav = $this;
Method createRedirect
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createRedirect($parentNavId, $navContainerId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget, $anchor = null): array|int
{
$_errors = [];
$nav = $this;
Method createModule
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createModule($parentNavId, $navContainerId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
{
$_errors = [];
$nav = $this;
Method createPageItem
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description): array|int
{
$_errors = [];
$navItem = new NavItem();
Function createPageFromDraft
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false): bool|array
{
if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) {
$isDraft = 0;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method createRedirect
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createRedirect($parentNavId, $navContainerId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget, $anchor = null): array|int
Method createModule
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createModule($parentNavId, $navContainerId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
Method createModuleItem
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
Method createRedirectItem
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget): array|int
{
$_errors = [];
$navItem = new NavItem();
Method createModuleItem
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
{
$_errors = [];
$navItem = new NavItem();
Method createPage
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false): array|int
Method createPageFromDraft
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false): bool|array
Method createRedirectItem
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget): array|int
Method createPageItem
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description): array|int
Function checkDuplicateAlias
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function checkDuplicateAlias($currentNavId, $parentNavId)
{
$currentNavItems = NavItem::find()->where(['nav_id' => $currentNavId])->asArray()->all();
foreach (self::find()->where(['parent_nav_id' => $parentNavId, 'is_deleted' => false])->andWhere(['<>', 'id', $currentNavId])->asArray()->all() as $item) {
foreach ($currentNavItems as $currentNavItem) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return $sourceNavItem->copyTypeContent($navItem);
Function createPage
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false): array|int
{
$_errors = [];
$nav = $this;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"