MappingException   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 46.15%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 21
c 1
b 0
f 0
dl 0
loc 74
ccs 12
cts 26
cp 0.4615
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fileMappingDriversRequireConfiguredDirectoryPath() 0 11 2
A mappingFileNotFound() 0 6 1
A invalidMappingFile() 0 6 1
A classNotFoundInNamespaces() 0 8 1
A pathRequired() 0 4 1
A nonExistingClass() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Persistence\Mapping;
6
7
use Exception;
8
use function implode;
9
use function sprintf;
10
11
/**
12
 * A MappingException indicates that something is wrong with the mapping setup.
13
 */
14
class MappingException extends Exception
15
{
16
    /**
17
     * @param array<int, string> $namespaces
18
     *
19
     * @return self
20
     */
21 1
    public static function classNotFoundInNamespaces(
22
        string $className,
23
        array $namespaces
24
    ) {
25 1
        return new self(sprintf(
26 1
            "The class '%s' was not found in the chain configured namespaces %s",
27 1
            $className,
28 1
            implode(', ', $namespaces)
29
        ));
30
    }
31
32
    /**
33
     * @return self
34
     */
35
    public static function pathRequired()
36
    {
37
        return new self('Specifying the paths to your entities is required ' .
38
            'in the AnnotationDriver to retrieve all class names.');
39
    }
40
41
    /**
42
     * @return self
43
     */
44
    public static function fileMappingDriversRequireConfiguredDirectoryPath(
45
        ?string $path = null
46
    ) {
47
        if ($path !== null) {
48
            $path = '[' . $path . ']';
49
        }
50
51
        return new self(sprintf(
52
            'File mapping drivers must have a valid directory path, ' .
53
            'however the given path %s seems to be incorrect!',
54
            $path
55
        ));
56
    }
57
58
    /**
59
     * @return self
60
     */
61 2
    public static function mappingFileNotFound(string $entityName, string $fileName)
62
    {
63 2
        return new self(sprintf(
64 2
            "No mapping file found named '%s' for class '%s'.",
65 2
            $fileName,
66 2
            $entityName
67
        ));
68
    }
69
70
    /**
71
     * @return self
72
     */
73
    public static function invalidMappingFile(string $entityName, string $fileName)
74
    {
75
        return new self(sprintf(
76
            "Invalid mapping file '%s' for class '%s'.",
77
            $fileName,
78
            $entityName
79
        ));
80
    }
81
82
    /**
83
     * @return self
84
     */
85 1
    public static function nonExistingClass(string $className)
86
    {
87 1
        return new self(sprintf("Class '%s' does not exist", $className));
88
    }
89
}
90