Completed
Push — master ( 86ebd4...251ea7 )
by Sebastian
02:41
created

NameHelper::identicalAuthors()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 2
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
1
<?php
2
/*
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2017 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Util;
11
12
/**
13
 * Class NameHelper
14
 * @package Seboettg\CiteProc\Util
15
 * @author Sebastian Böttger <[email protected]>
16
 */
17
class NameHelper
18
{
19
20
    /**
21
     * @param \stdClass $precedingItem
22
     * @param array $currentAuthor
23
     * @return bool
24
     */
25
    public static function identicalAuthors($precedingItem, $currentAuthor)
26
    {
27
        if (count($precedingItem->author) !== count($currentAuthor)) {
28
            return false;
29
        }
30
        foreach ($currentAuthor as $current) {
31
            if (self::precedingHasAuthor($precedingItem, $current)) {
32
                continue;
33
            }
34
            return false;
35
        }
36
        return true;
37
    }
38
39
    /**
40
     * @param \stdClass $preceding
41
     * @param \stdClass $name
42
     * @return bool
43
     */
44
    public static function precedingHasAuthor($preceding, $name)
45
    {
46
        foreach ($preceding->author as $author) {
47
            if ($author->family === $name->family && $author->given === $name->given) {
48
                return true;
49
            }
50
        }
51
        return false;
52
    }
53
}