Showing 246 of 247 total issues

Method join has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function join(
        $foreignTable,
        $masterField = null,
        $joinKind = null,
        $foreignAlias = null
Severity: Minor
Found in src/Persistence/Sql/Query.php - About 1 hr to fix

Method _addField has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function _addField(string $fieldName, bool $theirFieldIsTitle, ?string $theirFieldName, array $defaults): SqlExpressionField
    {
        $ourModel = $this->getOurModel();

        $fieldExpression = $ourModel->addExpression($fieldName, array_merge([
Severity: Minor
Found in src/Reference/HasOneSql.php - About 1 hr to fix

Method updateRenderBeforeExecute has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    protected function updateRenderBeforeExecute(array $render): array
    {
        [$sql, $params] = parent::updateRenderBeforeExecute($render);

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

Method ref has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    public function ref(Model $ourModelOrEntity, array $defaults = []): Model
    {
        $this->assertOurModelOrEntity($ourModelOrEntity);

Severity: Minor
Found in src/Reference/HasOne.php - About 1 hr to fix

Method getCreateAutoincrementSql has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    public function getCreateAutoincrementSql($name, $table, $start = 1)
    {
        $sqls = parent::getCreateAutoincrementSql($name, $table, $start);

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

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

    #[\Override]
    protected function escapeStringLiteral(string $value): string
    {
        // Oracle (multibyte) string literal is limited to 1332 bytes
        $parts = $this->splitLongString($value, 1000);
Severity: Minor
Found in src/Persistence/Sql/Oracle/ExpressionTrait.php - About 1 hr to fix

Method init has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    protected function init(): void
    {
        parent::init();

Severity: Minor
Found in src/Reference/HasOne.php - About 1 hr to fix

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

    protected function onHookToOwnerEntity(string $spot, \Closure $fx, array $args = [], int $priority = 5): int
    {
        $name = $this->shortName; // use static function to allow this object to be GCed

        return $this->getOwner()->onHookDynamic(
Severity: Major
Found in src/Model/Join.php and 1 other location - About 1 hr to fix
src/Field.php on lines 77..93

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 109.

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

    protected function onHookToOwnerEntity(string $spot, \Closure $fx, array $args = [], int $priority = 5): int
    {
        $name = $this->shortName; // use static function to allow this object to be GCed

        return $this->getOwner()->onHookDynamic(
Severity: Major
Found in src/Field.php and 1 other location - About 1 hr to fix
src/Model/Join.php on lines 201..218

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 109.

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

    private function _initQueryConditions(Query $query, Model\Scope\AbstractScope $condition): void
    {
        if (!$condition->isEmpty()) {
            // peel off the single nested scopes to convert (((field = value))) to field = value
            $condition = $condition->simplify();
Severity: Minor
Found in src/Persistence/Sql.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 _renderField has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _renderField($addAlias = true): string
    {
        // if no fields were defined, use defaultField
        if (($this->args['field'] ?? []) === []) {
            if ($this->defaultField instanceof Expression) {
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 order has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function order($order, $direction = null)
    {
        if (is_string($order) && str_contains($order, ',')) {
            throw new Exception('Comma-separated fields list is no longer accepted, use array instead');
        }
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 _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

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

    #[\Override]
    protected function init(): void
    {
        parent::init();

Severity: Minor
Found in src/Reference/HasOne.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 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function isIndexExists(array $fields, bool $requireUnique = false): bool
    {
        $fields = array_map(fn ($field) => $this->resolvePersistenceField($field), $fields);
        $tableName = 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 consume has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function consume($expr, string $escapeMode): string
    {
        if (!is_object($expr)) {
            switch ($escapeMode) {
                case self::ESCAPE_PARAM:
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 1 hr to fix

Method escapeStringLiteral has 35 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->explicitCastIsEncodedBinary($value), null, Persistence\Sql::class)()) {
Severity: Minor
Found in src/Persistence/Sql/Mssql/ExpressionTrait.php - About 1 hr to fix

Method getColumnComment has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    #[\Override]
    protected function getColumnComment(Column $column)
    {
        $tmpType = new class extends Type {
            private Type $type;
Severity: Minor
Found in src/Persistence/Sql/PlatformFixColumnCommentTypeHintTrait.php - About 1 hr to fix

Method makeHashFromKey has 34 lines of code (exceeds 25 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

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
Severity
Category
Status
Source
Language