Passed
Branch master (25273e)
by Mihail
04:42
created

Apps/ActiveRecord/ProfileField.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Helper\Serialize;
8
9
/**
10
 * Class ProfileField. Active record model for additional profile fields management
11
 * @package Apps\ActiveRecord
12
 * @property int $id
13
 * @property string $type
14
 * @property string $name
15
 * @property string $reg_exp
16
 * @property string $reg_cond
17
 * @property string $created_at
18
 * @property string $updated_at
19
 */
20
class ProfileField extends ActiveModel
21
{
22
23
    /**
24
     * Get all fields using memory cache
25
     * @return \Illuminate\Database\Eloquent\Collection|mixed|static[]
26
     */
27
    public static function getAll()
28
    {
29
        if (MainApp::$Memory->get('custom.fields.all') !== null) {
30
            return MainApp::$Memory->get('custom.fields.all');
31
        }
32
33
        $records = self::all();
34
        MainApp::$Memory->set('custom.fields.all', $records);
35
        return $records;
36
    }
37
38
    /**
39
     * Get field name locale by field id
40
     * @param int $id
41
     * @return array|null|string
42
     */
43 View Code Duplication
    public static function getNameById($id)
0 ignored issues
show
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...
44
    {
45
        $all = self::getAll();
46
47
        $record = $all->find($id);
48
        if ($record === null || $record === false) {
49
            return null;
50
        }
51
52
        return Serialize::getDecodeLocale($record->name);
53
    }
54
55
    /**
56
     * Get field type by field id
57
     * @param int $id
58
     * @return array|null|string
59
     */
60 View Code Duplication
    public static function getTypeById($id)
0 ignored issues
show
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...
61
    {
62
        $all = self::getAll();
63
64
        $record = $all->find($id);
65
        if ($record === null || $record === false) {
66
            return null;
67
        }
68
69
        return $record->type;
70
    }
71
72
}