EntityCollection   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A firstByAttribute() 0 10 1
1
<?php
2
/*
3
 * This file is part of the slince/smartqq package.
4
 *
5
 * (c) Slince <[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 Slince\SmartQQ;
12
13
use Cake\Collection\Collection;
14
15
class EntityCollection extends Collection
16
{
17
    /**
18
     * 根据实体属性筛选指定一个实体.
19
     *
20
     * @param string $attributeName
21
     * @param mixed  $attributeValue
22
     *
23
     * @return object|null
24
     */
25
    public function firstByAttribute($attributeName, $attributeValue)
26
    {
27
        $callback = function ($entity) use ($attributeName, $attributeValue) {
28
            $method = 'get'.ucfirst($attributeName);
29
30
            return $entity->$method() == $attributeValue;
31
        };
32
33
        return  $this->filter($callback)->first();
34
    }
35
}
36