Passed
Push — master ( a0dc52...1c8004 )
by Mike
19:12
created

Attendees   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 56
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 4 1
A add() 0 7 1
A toArray() 0 4 1
A toXmlString() 0 17 2
1
<?php
2
namespace mikemix\Wiziq\Entity;
3
4
class Attendees
5
{
6
    /** @var array */
7
    private $list = [];
8
9
    /**
10
     * @return Attendees
11
     */
12 5
    public static function build()
13
    {
14 5
        return new self();
15
    }
16
17
    /**
18
     * @param int    $id
19
     * @param string $name
20
     * @param string $languageCultureName
21
     * @return Attendees
22
     */
23 5
    public function add($id, $name, $languageCultureName = 'en-US')
24
    {
25 5
        $self = clone $this;
26 5
        $self->list[] = ['id' => (int)$id, 'name' => (string)$name, 'lang' => (string)$languageCultureName];
27
28 5
        return $self;
29
    }
30
31
    /**
32
     * @return array
33
     */
34 2
    public function toArray()
35
    {
36 2
        return $this->list;
37
    }
38
39
    /**
40
     * @return string
41
     */
42 1
    public function toXmlString()
43
    {
44 1
        $attendees = [];
45
46 1
        foreach ($this->list as $attendee) {
47 1
            $attendees[] = sprintf(
48
                '<attendee><attendee_id><![CDATA[%d]]></attendee_id>' .
49 1
                '<screen_name><![CDATA[%s]]></screen_name>' .
50 1
                '<language_culture_name><![CDATA[%s]]></language_culture_name></attendee>',
51 1
                $attendee['id'],
52 1
                $attendee['name'],
53 1
                $attendee['lang']
54 1
            );
55 1
        }
56
57 1
        return sprintf('<attendee_list>%s</attendee_list>', implode('', $attendees));
58
    }
59
}
60