Passed
Push — feature/more-precise-NoBeanFou... ( 7d6857 )
by Kevin
10:05
created

NoBeanFoundException::getClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TheCodingMachine\TDBM;
5
6
/**
7
 * An exception thrown if no rows are returned when TDBMService->findObjectOrFail is called.
8
 */
9
class NoBeanFoundException extends TDBMException
10
{
11
12
    private string $tableName;
13
    private string $className;
14
15
    /**
16
     * @var string[]
17
     */
18
    private array $primaryKeys;
19
20
    public static function missPrimaryKeyRecord(string $tableName, array $primaryKeys, string $className, $previous) : self
21
    {
22
        $primaryKeysStringified = implode(' and ', array_map(function ($key, $value) {
23
            return "'".$key."' = ".$value;
24
        }, array_keys($primaryKeys), $primaryKeys));
25
        $exception = new self("No result found for query on table '".$tableName."' for ".$primaryKeysStringified, 0, $previous);
26
        $exception->tableName = $tableName;
27
        $exception->primaryKeys = $primaryKeys;
28
        $exception->className = $className;
29
30
        return $exception;
31
    }
32
33
    public static function missFilterRecord(string $tableName) : self
34
    {
35
        return new self("No result found for query on table '".$tableName."'");
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getTableName(): string
42
    {
43
        return $this->tableName;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getClassName(): string
50
    {
51
        return $this->className;
52
    }
53
54
    /**
55
     * @return string[]
56
     */
57
    public function getPrimaryKeys(): array
58
    {
59
        return $this->primaryKeys;
60
    }
61
62
}
63