1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \Wicked\Timely\PushServices\PushServiceFactory |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author wick-ed |
15
|
|
|
* @copyright 2019 Bernhard Wick |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/wick-ed/timely |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Wicked\Timely\PushServices; |
21
|
|
|
|
22
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
23
|
|
|
use Wicked\Timely\DotEnvConfiguration; |
24
|
|
|
use Wicked\Timely\PushServices\Authentication\MacOsPasswordRetrievalStrategy; |
25
|
|
|
use Wicked\Timely\PushServices\Authentication\UnixPasswordRetrievalStrategy; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Push Service factory |
29
|
|
|
* |
30
|
|
|
* @author wick-ed |
31
|
|
|
* @copyright 2019 Bernhard Wick |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/wick-ed/timely |
34
|
|
|
*/ |
35
|
|
|
class PushServiceFactory |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get a push service as configured |
40
|
|
|
* |
41
|
|
|
* @return PushServiceInterface |
42
|
|
|
* |
43
|
|
|
* @throws \JiraRestApi\JiraException |
44
|
|
|
*/ |
45
|
|
|
public static function getService(OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
$configuration = new DotEnvConfiguration(); |
48
|
|
|
|
49
|
|
|
$passwordRetrievalStrategy = new UnixPasswordRetrievalStrategy($output, $configuration); |
50
|
|
|
if (static::getOs() === 'Darwin') { |
51
|
|
|
$passwordRetrievalStrategy = new MacOsPasswordRetrievalStrategy($output, $configuration); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$pushService = $configuration->getPushService(); |
55
|
|
|
switch ($pushService) { |
56
|
|
|
case 'jira': |
57
|
|
|
$pushService = new Jira($passwordRetrievalStrategy); |
58
|
|
|
break; |
59
|
|
|
|
60
|
|
|
default: |
61
|
|
|
throw new \Exception(sprintf('Cannot create push service instance for "%s" configuration value', $pushService)); |
62
|
|
|
break; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $pushService; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Detect the host OS. |
70
|
|
|
* Returns any of 'Windows', 'Darwin', 'Linux' or 'Unknown'. |
71
|
|
|
* Intentionally kept the same as PHP_OS_FAMILY to be substituted when PHP < 7.2 isn't a thing anymore. |
72
|
|
|
* @see https://www.php.net/manual/en/reserved.constants.php#constant.php-os-family |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
protected static function getOs() |
77
|
|
|
{ |
78
|
|
|
$osString = php_uname('s'); |
79
|
|
|
if (strpos($osString, 'Darwin') === 0) { |
80
|
|
|
return 'Darwin'; |
81
|
|
|
} |
82
|
|
|
if (strpos($osString, 'Windows') === 0) { |
83
|
|
|
return 'Windows'; |
84
|
|
|
} |
85
|
|
|
if (strpos($osString, 'Linux') === 0) { |
86
|
|
|
return 'Linux'; |
87
|
|
|
} |
88
|
|
|
return 'Unknown'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.