src/Model.php

Summary

Maintainability
F
5 days
Test Coverage

File Model.php has 1197 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

<?php

declare(strict_types=1);

namespace Atk4\Data;
Severity: Major
Found in src/Model.php - About 3 days to fix

Model has 91 functions (exceeds 20 allowed). Consider refactoring.
Open

class Model implements \IteratorAggregate
{
    use CollectionTrait {
        _addIntoCollection as private __addIntoCollection;
    }
Severity: Major
Found in src/Model.php - About 1 day to fix

Function export has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    public function export(?array $fields = null, ?string $keyField = null, bool $typecast = true): array
    {
        $this->assertHasPersistence('export');

        // no key field - then just do export
Severity: Minor
Found in src/Model.php - About 5 hrs to fix

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 save has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function save(array $data = [])
    {
        $this->getModel()->assertIsWriteable();
        $this->getModel()->assertHasPersistence();

Severity: Major
Found in src/Model.php - About 2 hrs to fix

Function createIteratorBy has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function createIteratorBy($field, $operator = null, $value = null): \Traversable
    {
        $this->assertIsModel();

        $scopeOrig = null;
Severity: Minor
Found in src/Model.php - About 2 hrs to fix

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

Function setOrder has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function setOrder($field, string $direction = 'asc')
    {
        $this->assertIsModel();

        // fields passed as array
Severity: Minor
Found in src/Model.php - About 1 hr to fix

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 export has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function export(?array $fields = null, ?string $keyField = null, bool $typecast = true): array
    {
        $this->assertHasPersistence('export');

        // no key field - then just do export
Severity: Minor
Found in src/Model.php - About 1 hr to fix

Method createIteratorBy has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function createIteratorBy($field, $operator = null, $value = null): \Traversable
    {
        $this->assertIsModel();

        $scopeOrig = null;
Severity: Minor
Found in src/Model.php - About 1 hr to fix

Method _load has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function _load(bool $fromReload, bool $fromTryLoad, $id)
    {
        $this->getModel()->assertHasPersistence();
        if ($this->isLoaded()) {
            throw new Exception('Entity must be unloaded');
Severity: Minor
Found in src/Model.php - About 1 hr to fix

Function _load has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    private function _load(bool $fromReload, bool $fromTryLoad, $id)
    {
        $this->getModel()->assertHasPersistence();
        if ($this->isLoaded()) {
            throw new Exception('Entity must be unloaded');
Severity: Minor
Found in src/Model.php - About 1 hr to fix

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

Consider simplifying this complex logical expression.
Open

                if (($f === 'system' && $field->system)
                    || ($f === 'not system' && !$field->system)
                    || ($f === 'editable' && $field->isEditable())
                    || ($f === 'visible' && $field->isVisible())
                ) {
Severity: Critical
Found in src/Model.php - About 1 hr to fix

Method set has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function set(string $field, $value)
    {
        $this->getModel()->assertOnlyField($field);

        $f = $this->getField($field);
Severity: Minor
Found in src/Model.php - About 1 hr to fix

Method setOrder has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setOrder($field, string $direction = 'asc')
    {
        $this->assertIsModel();

        // fields passed as array
Severity: Minor
Found in src/Model.php - About 1 hr to fix

Method getFields has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getFields($filter = null): array
    {
        if ($this->isEntity()) {
            return $this->getModel()->getFields($filter);
        }
Severity: Minor
Found in src/Model.php - About 1 hr to fix

Function set has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function set(string $field, $value)
    {
        $this->getModel()->assertOnlyField($field);

        $f = $this->getField($field);
Severity: Minor
Found in src/Model.php - About 45 mins to fix

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

Function _insert has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _insert(array $row): void
    {
        // find any row values that do not correspond to fields, they may correspond to references instead
        $refs = [];
        foreach ($row as $key => $value) {
Severity: Minor
Found in src/Model.php - About 35 mins to fix

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 $this;
Severity: Major
Found in src/Model.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return null;
Severity: Major
Found in src/Model.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return $this;
Severity: Major
Found in src/Model.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return $res;
Severity: Major
Found in src/Model.php - About 30 mins to fix

Function insert has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function insert(array $row)
    {
        $entity = $this->createEntity();

        $hasRefs = false;
Severity: Minor
Found in src/Model.php - About 25 mins to fix

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

Function getModelOnlyProperties has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getModelOnlyProperties(): array
    {
        $this->assertIsModel();

        if ((self::$_modelOnlyProperties ?? null) === null) {
Severity: Minor
Found in src/Model.php - About 25 mins to fix

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

There are no issues that match your filters.

Category
Status