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