Passed
Pull Request — master (#380)
by Wilmer
03:46 queued 01:08
created

Schema::getLastInsertID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Support\Stubs;
6
7
use Yiisoft\Db\Cache\SchemaCache;
8
use Yiisoft\Db\Connection\ConnectionInterface;
9
use Yiisoft\Db\Constraint\Constraint;
10
use Yiisoft\Db\Exception\NotSupportedException;
11
use Yiisoft\Db\Schema\ColumnSchemaBuilder;
12
use Yiisoft\Db\Schema\SchemaInterface;
13
use Yiisoft\Db\Schema\TableSchemaInterface;
14
15
final class Schema extends \Yiisoft\Db\Schema\Schema implements SchemaInterface
16
{
17
    public function __construct(ConnectionInterface $connection, SchemaCache $schemaCache)
18
    {
19
        parent::__construct($connection, $schemaCache);
20
    }
21
22
    public function createColumnSchemaBuilder(string $type, array|int|string $length = null): ColumnSchemaBuilder
23
    {
24
        return new ColumnSchemaBuilder($type, $length);
25
    }
26
27
    public function findUniqueIndexes(TableSchemaInterface $table): array
28
    {
29
        return $this->getException(self::class . '::findUniqueIndexes()' . ' is not supported by core-db.');
30
    }
31
32
    public function getLastInsertID(string $sequenceName = null): string
0 ignored issues
show
Unused Code introduced by
The parameter $sequenceName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

32
    public function getLastInsertID(/** @scrutinizer ignore-unused */ string $sequenceName = null): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        $this->getException(self::class . '::getLastInsertID() is not supported by core-db.');
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
35
    }
36
37
    protected function getCacheKey(string $name): array
38
    {
39
        return [];
40
    }
41
42
    protected function getCacheTag(): string
43
    {
44
        return '';
45
    }
46
47
    protected function loadTableChecks(string $tableName): array
48
    {
49
        $this->getException(self::class . '::loadTableChecks() is not supported by core-db.');
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
50
    }
51
52
    protected function loadTableDefaultValues(string $tableName): array
53
    {
54
        $this->getException(self::class . '::loadTableDefaultValues() is not supported by core-db.');
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
55
    }
56
57
    protected function loadTableForeignKeys(string $tableName): array
58
    {
59
        $this->getException(self::class . '::loadTableForeignKeys() is not supported by core-db.');
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
60
    }
61
62
    protected function loadTableIndexes(string $tableName): array
63
    {
64
        $this->getException();
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
Bug introduced by
The call to Yiisoft\Db\Tests\Support...\Schema::getException() has too few arguments starting with message. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        $this->/** @scrutinizer ignore-call */ 
65
               getException();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
65
    }
66
67
    protected function loadTablePrimaryKey(string $tableName): Constraint|null
68
    {
69
        $this->getException(self::class . '::loadTablePrimaryKey() is not supported by core-db.');
70
    }
71
72
    protected function loadTableUniques(string $tableName): array
73
    {
74
        $this->getException(self::class . '::loadTableUniques() is not supported by core-db.');
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
75
    }
76
77
    protected function loadTableSchema(string $name): TableSchemaInterface|null
78
    {
79
        $this->getException(self::class . '::loadTableSchema() is not supported by core-db.');
80
    }
81
82
    private function getException(string $message): void
83
    {
84
        throw new NotSupportedException($message);
85
    }
86
}
87