Showing 250 of 251 total issues

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

    #[\Override]
    public function tryLoad(Model $model, $id): ?array
    {
        $model->assertIsModel();

Severity: Minor
Found in src/Persistence/Array_.php - About 1 hr to fix

Method escapeStringLiteral has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    protected function escapeStringLiteral(string $value): string
    {
        $dummyPersistence = (new \ReflectionClass(Persistence\Sql::class))->newInstanceWithoutConstructor();
        if (\Closure::bind(static fn () => $dummyPersistence->binaryTypeValueIsEncoded($value), null, Persistence\Sql::class)()) {
Severity: Minor
Found in src/Persistence/Sql/Postgresql/ExpressionTrait.php - About 1 hr to fix

Method _renderConditionBinary has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override] // @phpstan-ignore-line https://github.com/phpstan/phpstan/issues/10942
    protected function _renderConditionBinary(string $operator, string $sqlLeft, $sqlRight): string
    {
        if (in_array($operator, ['in', 'not in'], true)) {
            if (is_array($sqlRight)) {
Severity: Minor
Found in src/Persistence/Sql/Sqlite/Query.php - About 1 hr to fix

Method match has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function match(array $row, Model\Scope\AbstractScope $condition): bool
    {
        if ($condition instanceof Model\Scope\Condition) { // simple condition
            $args = $condition->toQueryArguments();

Severity: Minor
Found in src/Persistence/Array_/Action.php - About 1 hr to fix

Method _renderConditionLikeOperator has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    protected function _renderConditionLikeOperator(bool $negated, string $sqlLeft, string $sqlRight): string
    {
        return ($negated ? 'not ' : '') . $this->_renderConditionBinaryReuse(
            $sqlLeft,
Severity: Minor
Found in src/Persistence/Sql/Sqlite/Query.php - About 1 hr to fix

Method wrap has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    public function wrap(Driver $driver): Driver
    {
        return new class($driver) extends AbstractDriverMiddleware {
            #[\Override]
Severity: Minor
Found in src/Persistence/Sql/Sqlite/CreateRegexpLikeFunctionMiddleware.php - About 1 hr to fix

Method deduplicateAnalysingKey has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function deduplicateAnalysingKey(array $analysingKey, object $analysingOwner): array
    {
        if ((self::$analysingClosureMap ?? null) === null) {
            self::$analysingClosureMap = new WeakAnalysingMap();
        }
Severity: Minor
Found in src/Reference.php - About 1 hr to fix

Method initUserActions has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function initUserActions(): void
    {
        // declare our basic CRUD actions for the model
        $this->addUserAction('add', [
            'fields' => true,
Severity: Minor
Found in src/Model/UserActionsTrait.php - About 1 hr to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getReferences(): array
    {
        $this->assertIsModel();

        $res = [];
Severity: Major
Found in src/Model/ReferencesTrait.php and 1 other location - About 1 hr to fix
src/Model/JoinsTrait.php on lines 73..88

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 106.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getJoins(): array
    {
        $this->assertIsModel();

        $res = [];
Severity: Major
Found in src/Model/JoinsTrait.php and 1 other location - About 1 hr to fix
src/Model/ReferencesTrait.php on lines 128..143

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 106.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function addField has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function addField(string $fieldName, array $defaults = []): Field
    {
        if (!isset($defaults['aggregate']) && !isset($defaults['concat']) && !isset($defaults['expr'])) {
            throw (new Exception('Aggregate field requires "aggregate", "concat" or "expr" specified to hasMany()->addField()'))
                ->addMoreInfo('field', $fieldName)
Severity: Minor
Found in src/Reference/HasMany.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

Function makeHashFromKey has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function makeHashFromKey($value, ?\HashContext $hashContext = null): ?int
    {
        if ($hashContext === null) {
            $hashContext = hash_init('crc32c');
            $return = true;
Severity: Minor
Found in src/Reference/WeakAnalysingMap.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

Function saveRow has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    private function saveRow(Model $model, array $rowData, $id): void
    {
        if ($model->idField) {
            $idField = $model->getIdField();
            $id = $idField->normalize($id);
Severity: Minor
Found in src/Persistence/Array_.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

Function restoreSequencesIfDecremented has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function restoreSequencesIfDecremented(array $beforeRollbackSequences): void
    {
        $afterRollbackSequences = $this->listSequences();

        foreach ($beforeRollbackSequences as $schema => $beforeRollbackSequences2) {

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 _renderTable has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _renderTable($addAlias = true): ?string
    {
        $res = [];
        foreach ($this->args['table'] ?? [] as $alias => $table) {
            if ($addAlias === false && $table instanceof self) {
Severity: Minor
Found in src/Persistence/Sql/Query.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

Function tryLoad has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    #[\Override]
    public function tryLoad(Model $model, $id): ?array
    {
        $model->assertIsModel();

Severity: Minor
Found in src/Persistence/Array_.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

Function _renderConditionBinaryReuse has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _renderConditionBinaryReuse(
        string $sqlLeft,
        string $sqlRight,
        \Closure $makeSqlFx,
        bool $allowReuseLeft = true,
Severity: Minor
Found in src/Persistence/Sql/Query.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

Function isIndexExists has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function isIndexExists(array $fields, bool $requireUnique): bool
    {
        $fields = array_map(fn ($field) => $this->resolvePersistenceField($field), $fields);
        $table = reset($fields)->getOwner()->table;

Severity: Minor
Found in src/Schema/Migrator.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 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
Severity
Category
Status
Source
Language