Getter::getForeignModels()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/*
3
 * This file is part of the Scrawler package.
4
 *
5
 * (c) Pranjal Pandey <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Scrawler\Arca\Traits\Model;
12
13
use Scrawler\Arca\Collection;
14
15
/**
16
 * Getter trait to provide getter methods to the model.
17
 */
18
trait Getter
19
{
20
    /**
21
     * Get current model Id or UUID.
22
     */
23
    public function getId(): mixed
24
    {
25
        return $this->__meta['id'];
26
    }
27
28
    /**
29
     * Get current table name of model.
30
     */
31
    public function getName(): string
32
    {
33
        return $this->table;
34
    }
35
36
    /**
37
     * Get all properties with relational models in array form.
38
     *
39
     * @return array<mixed>
40
     */
41
    public function getProperties(): array
42
    {
43
        return $this->__properties['all'];
44
    }
45
46
    /**
47
     * Get self properties without relations in array form.
48
     *
49
     * @return array<mixed>
50
     */
51
    public function getSelfProperties(): array
52
    {
53
        return $this->__properties['self'];
54
    }
55
56
    /**
57
     * Get all property types in array form.
58
     *
59
     * @return array<mixed>
60
     */
61
    public function getTypes(): array
62
    {
63
        return $this->__properties['type'];
64
    }
65
66
    /**
67
     * returns all relational models.
68
     */
69
    public function getForeignModels(string $type): Collection
70
    {
71
        return is_null($this->__meta['foreign_models'][$type]) ? Collection::fromIterable([]) : $this->__meta['foreign_models'][$type];
72
    }
73
}
74