Appveyor::getTimestamp()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace MatthiasMullie\CI\Providers;
4
5
use MatthiasMullie\CI\Environment;
6
7
/**
8
 * @see http://www.appveyor.com/docs/environment-variables
9
 *
10
 * @author Matthias Mullie <[email protected]>
11
 * @copyright Copyright (c) 2016, Matthias Mullie. All rights reserved.
12
 * @license LICENSE MIT
13
 */
14
class Appveyor extends None implements Environment
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public static function isCurrent()
20
    {
21
        return getenv('APPVEYOR') === 'True';
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getProvider()
28
    {
29
        return 'appveyor';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getSlug()
36
    {
37
        return getenv('APPVEYOR_REPO_NAME');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getBranch()
44
    {
45
        return $this->getPullRequest() === '' ? getenv('APPVEYOR_REPO_BRANCH') : '';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getPullRequest()
52
    {
53
        return getenv('APPVEYOR_PULL_REQUEST_NUMBER') ?: '';
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getCommit()
60
    {
61
        return getenv('APPVEYOR_REPO_COMMIT');
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getAuthor()
68
    {
69
        return getenv('APPVEYOR_REPO_COMMIT_AUTHOR');
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getAuthorEmail()
76
    {
77
        return getenv('APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL');
78
    }
79
80
    /**
81
     * Appveyor has a APPVEYOR_REPO_COMMIT_TIMESTAMP, but it contains this:
82
     * Expected:                       2016-02-18T16:18:39+01:00
83
     * APPVEYOR_REPO_COMMIT_TIMESTAMP: 2016-02-18T15:18:39.0000000Z
84
     * Note how it converted the time to UTC (and has some weird formatting
85
     * where it adds decimal fraction to the minutes...)
86
     * I decided against using APPVEYOR_REPO_COMMIT_TIMESTAMP and just using
87
     * what git gives us and only keep it around as fallback (though it should
88
     * never be used).
89
     *
90
     * {@inheritdoc}
91
     */
92
    public function getTimestamp()
93
    {
94
        return parent::getTimestamp() ?: getenv('APPVEYOR_REPO_COMMIT_TIMESTAMP');
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function getBuild()
101
    {
102
        return getenv('APPVEYOR_BUILD_NUMBER');
103
    }
104
}
105