Has::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
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