Passed
Push — master ( 347935...cc7747 )
by Mihail
05:42
created

ProfileField::all()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 11
loc 11
rs 9.4285
1
<?php
2
3
namespace Apps\ActiveRecord;
4
5
use Ffcms\Core\App as MainApp;
6
use Ffcms\Core\Arch\ActiveModel;
7
use Ffcms\Core\Cache\MemoryObject;
8
use Ffcms\Core\Helper\Serialize;
9
10
/**
11
 * Class ProfileField. Active record model for additional profile fields management
12
 * @package Apps\ActiveRecord
13
 * @property int $id
14
 * @property string $type
15
 * @property string $name
16
 * @property string $reg_exp
17
 * @property string $reg_cond
18
 * @property string $created_at
19
 * @property string $updated_at
20
 */
21
class ProfileField extends ActiveModel
22
{
23
24
    /**
25
     * Get all table data using memory cache
26
     * @param array $columns
27
     * @return \Illuminate\Database\Eloquent\Collection|mixed|static[]
28
     */
29 View Code Duplication
    public static function all($columns = ['*'])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $cacheName = 'activerecord.profilefield.all.' . implode('.', $columns);
32
        $records = MemoryObject::instance()->get($cacheName);
33
        if ($records === null) {
34
            $records = parent::all($columns);
35
            MemoryObject::instance()->set($cacheName, $records);
36
        }
37
38
        return $records;
39
    }
40
41
    /**
42
     * @deprecated
43
     * @return \Illuminate\Database\Eloquent\Collection|mixed|static[]
44
     */
45
    public static function getAll()
46
    {
47
        return self::all();
48
    }
49
50
    /**
51
     * Get field name locale by field id
52
     * @param int $id
53
     * @return array|null|string
54
     */
55
    public static function getNameById($id)
56
    {
57
        $all = self::all();
58
59
        $record = $all->find($id);
60
        if ($record === null || $record === false) {
61
            return null;
62
        }
63
64
        return Serialize::getDecodeLocale($record->name);
65
    }
66
67
    /**
68
     * Get field type by field id
69
     * @param int $id
70
     * @return array|null|string
71
     */
72
    public static function getTypeById($id)
73
    {
74
        $all = self::all();
75
76
        $record = $all->find($id);
77
        if ($record === null || $record === false) {
78
            return null;
79
        }
80
81
        return $record->type;
82
    }
83
84
}