SchemaAnalyzerTableNotFoundException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A tableNotFound() 0 15 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