tableNotFound()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 3
1
<?php
2
3
namespace Mouf\Database\SchemaAnalyzer;
4
5
use Doctrine\DBAL\Schema\Schema;
6
7
class SchemaAnalyzerTableNotFoundException extends SchemaAnalyzerException
8
{
9
    public static function tableNotFound($tableName, Schema $schema, \Exception $previousException = null)
10
    {
11
        $closestTableName = '';
12
        $closestScore = INF;
13
        foreach ($schema->getTables() as $testedTable) {
14
            $testedTableName = $testedTable->getName();
15
            $l = levenshtein($testedTableName, $tableName);
16
            if ($l < $closestScore) {
17
                $closestScore = $l;
18
                $closestTableName = $testedTableName;
19
            }
20
        }
21
22
        return new self("Could not find table '$tableName'. Did you mean '$closestTableName'?", 0, $previousException);
23
    }
24
}
25