src/Schema/Migrator.php

Summary

Maintainability
D
2 days
Test Coverage

File Migrator.php has 384 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Atk4\Data\Schema;
Severity: Minor
Found in src/Schema/Migrator.php - About 5 hrs to fix

Migrator has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

class Migrator
{
    public const REF_TYPE_NONE = 0;
    public const REF_TYPE_LINK = 1;
    public const REF_TYPE_PRIMARY = 2;
Severity: Minor
Found in src/Schema/Migrator.php - About 2 hrs to fix

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

    public function setModel(Model $model): Model
    {
        $this->table($model->table);

        foreach ($model->getFields() as $field) {
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

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

    public function drop(bool $dropForeignKeysFirst = false): self
    {
        $schemaManager = $this->createSchemaManager();

        if ($dropForeignKeysFirst) {
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

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

    public function createForeignKey($relation): void
    {
        [$localField, $foreignField] = is_array($relation)
            ? $relation
            : $this->resolveRelationDirection($relation);
Severity: Minor
Found in src/Schema/Migrator.php - About 1 hr to fix

Method field has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function field(string $fieldName, array $options = []): self
    {
        $type = $options['type'] ?? 'string';
        unset($options['type']);
        if ($type === 'time' && $this->getDatabasePlatform() instanceof OraclePlatform) {
Severity: Minor
Found in src/Schema/Migrator.php - About 1 hr to fix

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

    public function setModel(Model $model): Model
    {
        $this->table($model->table);

        foreach ($model->getFields() as $field) {
Severity: Minor
Found in src/Schema/Migrator.php - About 1 hr to fix

Function field has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function field(string $fieldName, array $options = []): self
    {
        $type = $options['type'] ?? 'string';
        unset($options['type']);
        if ($type === 'time' && $this->getDatabasePlatform() instanceof OraclePlatform) {
Severity: Minor
Found in src/Schema/Migrator.php - About 55 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 createIndex has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

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

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

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

    protected function stripDatabaseFromTableName(string $tableName): string
    {
        $platform = $this->getDatabasePlatform();
        $lastDotPos = strrpos($tableName, '.');
        if ($lastDotPos !== false) {
Severity: Minor
Found in src/Schema/Migrator.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

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

    public function __construct(object $source)
    {
        if ($source instanceof Connection) {
            $this->_connection = $source;
        } elseif ($source instanceof Persistence\Sql) {
Severity: Minor
Found in src/Schema/Migrator.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 resolveRelationDirection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function resolveRelationDirection(object $relation): array
    {
        if ($relation instanceof HasOne) {
            $localField = $relation->getOwner()->getField($relation->getOurFieldName());
            $theirModel = $relation->createTheirModel();
Severity: Minor
Found in src/Schema/Migrator.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