Completed
Push — master ( 93fabc...79ec86 )
by Vitaly
02:35
created

Field::byName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4286
cc 2
eloc 3
nc 2
nop 3
1
<?php
2
namespace samsoncms\api;
3
4
use samsonframework\orm\Condition;
5
use samsonframework\orm\QueryInterface;
6
7
/**
8
 * SamsonCMS additional field table entity class
9
 * @package samson\cms
10
 */
11
class Field extends \samson\activerecord\field
12
{
13
    /**
14
     * Find additional field database record by Name.
15
     * This is generic method that should be used in nested classes to find its
16
     * records by some its primary key value.
17
     *
18
     * @param QueryInterface $query Query object instance
19
     * @param string $name Additional field name
20
     * @param self $return Variable to return found database record
21
     * @return bool|null|self  Field instance or null if 3rd parameter not passed
22
     */
23 View Code Duplication
    public static function byName(QueryInterface $query, $name, self & $return = null)
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...
24
    {
25
        // Get field record by name column
26
        $return = static::oneByColumn($query, 'Name', $name);
27
28
        // If only one argument is passed - return null, otherwise bool
29
        return func_num_args() > 1 ? $return == null : $return;
30
    }
31
32
    /**
33
     * Find additional field database record by Name or ID.
34
     * This is generic method that should be used in nested classes to find its
35
     * records by some its primary key value.
36
     *
37
     * @param QueryInterface $query Query object instance
38
     * @param string $nameOrID Additional field name or identifier
39
     * @param self $return Variable to return found database record
40
     * @return bool|null|self  Field instance or null if 3rd parameter not passed
41
     */
42 View Code Duplication
    public static function byNameOrID(QueryInterface $query, $nameOrID, self & $return = null)
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...
43
    {
44
        // Create id or URL condition
45
        $idOrUrl = new Condition('OR');
46
        $idOrUrl->add('FieldID', $nameOrID)->add('Name', $field);
0 ignored issues
show
Bug introduced by
The variable $field does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
47
48
        // Perform query
49
        $return = $query->className('field')->cond($idOrUrl)->first();
0 ignored issues
show
Bug introduced by
The method className() does not seem to exist on object<samsonframework\orm\QueryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
        // If only one argument is passed - return null, otherwise bool
52
        return func_num_args() > 1 ? $return == null : $return;
53
    }
54
}
55