Has   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A many() 0 5 1
A one() 0 5 1
A __construct() 0 1 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapper\Instruction;
5
6
use Stratadox\Hydration\Mapper\Instruction\Relation\HasMany;
7
use Stratadox\Hydration\Mapper\Instruction\Relation\HasOne;
8
use Stratadox\HydrationMapper\DefinesRelationships;
9
use Stratadox\HydrationMapper\FindsKeys;
10
11
/**
12
 * Accessor for HasOne and HasMany objects, essentially syntax sugar.
13
 *
14
 * @package Stratadox\Hydrate
15
 * @author  Stratadox
16
 */
17
final class Has
18
{
19
    private function __construct() {}
20
21
    /**
22
     * Defines a has-one relationship with another class.
23
     *
24
     * @param string         $class The fully qualified class name.
25
     * @param FindsKeys|null $key   The input array offset (optional)
26
     * @return DefinesRelationships The relationship definition.
27
     */
28
    public static function one(
29
        string $class,
30
        FindsKeys $key = null
31
    ): DefinesRelationships {
32
        return HasOne::ofThe($class, $key);
33
    }
34
35
    /**
36
     * Defines a has-many relationship with another class.
37
     *
38
     * @param string         $class The fully qualified class name.
39
     * @param FindsKeys|null $key   The input array offset (optional)
40
     * @return DefinesRelationships The relationship definition.
41
     */
42
    public static function many(
43
        string $class,
44
        FindsKeys $key = null
45
    ): DefinesRelationships {
46
        return HasMany::ofThe($class, $key);
47
    }
48
}
49