Birthday   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasYear() 0 3 1
A hasDate() 0 3 1
A __construct() 0 8 3
1
<?php
2
/**
3
 * Copyright 2017 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 */
23
namespace Facebook\GraphNode;
24
25
use DateTime;
26
27
/**
28
 * Birthday object to handle various Graph return formats.
29
 *
30
 * @package Facebook
31
 */
32
class Birthday extends DateTime
33
{
34
    /**
35
     * @var bool
36
     */
37
    private $hasDate = false;
38
39
    /**
40
     * @var bool
41
     */
42
    private $hasYear = false;
43
44
    /**
45
     * Parses Graph birthday format to set indication flags, possible values:.
46
     *
47
     *  MM/DD/YYYY
48
     *  MM/DD
49
     *  YYYY
50
     *
51
     * @link https://developers.facebook.com/docs/graph-api/reference/user
52
     *
53
     * @param string $date
54
     */
55 4
    public function __construct($date)
56
    {
57 4
        $parts = explode('/', $date);
58
59 4
        $this->hasYear = count($parts) === 3 || count($parts) === 1;
60 4
        $this->hasDate = count($parts) === 3 || count($parts) === 2;
61
62 4
        parent::__construct($date);
63 4
    }
64
65
    /**
66
     * Returns whether date object contains birth day and month.
67
     *
68
     * @return bool
69
     */
70 3
    public function hasDate()
71
    {
72 3
        return $this->hasDate;
73
    }
74
75
    /**
76
     * Returns whether date object contains birth year.
77
     *
78
     * @return bool
79
     */
80 3
    public function hasYear()
81
    {
82 3
        return $this->hasYear;
83
    }
84
}
85