Factory::isDefaultMapping()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
namespace Vsmoraes\DynamoMapper\Mappings;
3
4
use ICanBoogie\Inflector;
5
use Vsmoraes\DynamoMapper\Exception\InvalidAttributeType;
6
7
class Factory
8
{
9
    const DEFAULT_NAMESPACE = '\Vsmoraes\DynamoMapper\Mappings';
10
11
    /**
12
     * @param string $type
13
     * @return Mapping
14
     * @throws InvalidAttributeType
15
     */
16
    public function make(string $type): Mapping
17
    {
18
        if ($mapClass = $this->isDefaultMapping($type)) {
19
            return new $mapClass;
20
        }
21
22
        $customMapping = $this->getCustomMapping($type);
23
        if (!is_null($customMapping) && $customMapping instanceof Mapping) {
24
            return $customMapping;
25
        }
26
27
        throw new InvalidAttributeType("The attribute type '{$type}' is not supported");
28
    }
29
30
    /**
31
     * @param string $type
32
     * @return string|null
33
     */
34
    protected function isDefaultMapping(string $type)
35
    {
36
        $className = sprintf(
37
            '%s\%sMapping',
38
            static::DEFAULT_NAMESPACE,
39
            Inflector::get()->camelize($type)
40
        );
41
42
        return class_exists($className) ? $className : null;
43
    }
44
45
    /**
46
     * You can extend this class and override this method
47
     * to make your own custom mappings
48
     *
49
     * @see StringMapping for an example
50
     *
51
     * @param string $type
52
     * @return mixed|null
53
     */
54
    public function getCustomMapping($type)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

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

Loading history...
55
    {
56
        return null;
57
    }
58
}
59