These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Part of the Joomla Framework Github Package |
||
4 | * |
||
5 | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
||
6 | * @license GNU General Public License version 2 or later; see LICENSE |
||
7 | */ |
||
8 | |||
9 | namespace Joomla\Github; |
||
10 | |||
11 | use Joomla\Registry\Registry; |
||
12 | |||
13 | /** |
||
14 | * Joomla Framework class for interacting with a GitHub server instance. |
||
15 | * |
||
16 | * @property-read Package\Activity $activity GitHub API object for the activity package. |
||
17 | * @property-read Package\Authorization $authorization GitHub API object for the authorizations package. |
||
18 | * @property-read Package\Data $data GitHub API object for the data package. |
||
19 | * @property-read Package\Emojis $emojis GitHub API object for the emojis package. |
||
20 | * @property-read Package\Gists $gists GitHub API object for the gists package. |
||
21 | * @property-read Package\Gitignore $gitignore GitHub API object for the gitignore package. |
||
22 | * @property-read Package\Issues $issues GitHub API object for the issues package. |
||
23 | * @property-read Package\Markdown $markdown GitHub API object for the markdown package. |
||
24 | * @property-read Package\Meta $meta GitHub API object for the meta package. |
||
25 | * @property-read Package\Orgs $orgs GitHub API object for the orgs package. |
||
26 | * @property-read Package\Pulls $pulls GitHub API object for the pulls package. |
||
27 | * @property-read Package\Repositories $repositories GitHub API object for the repositories package. |
||
28 | * @property-read Package\Search $search GitHub API object for the search package. |
||
29 | * @property-read Package\Users $users GitHub API object for the users package. |
||
30 | * @property-read Package\Zen $zen GitHub API object for the zen package. |
||
31 | * |
||
32 | * @since 1.0 |
||
33 | */ |
||
34 | class Github |
||
35 | { |
||
36 | /** |
||
37 | * @var array Options for the GitHub object. |
||
38 | * @since 1.0 |
||
39 | */ |
||
40 | protected $options; |
||
41 | |||
42 | /** |
||
43 | * @var Http The HTTP client object to use in sending HTTP requests. |
||
44 | * @since 1.0 |
||
45 | */ |
||
46 | protected $client; |
||
47 | |||
48 | /** |
||
49 | * Constructor. |
||
50 | * |
||
51 | * @param Registry $options GitHub options object. |
||
52 | * @param Http $client The HTTP client object. |
||
53 | * |
||
54 | * @since 1.0 |
||
55 | */ |
||
56 | public function __construct(Registry $options = null, Http $client = null) |
||
57 | { |
||
58 | $this->options = isset($options) ? $options : new Registry; |
||
59 | $this->client = isset($client) ? $client : new Http($this->options); |
||
60 | |||
61 | // Setup the default API url if not already set. |
||
62 | if (!$this->getOption('api.url')) |
||
63 | { |
||
64 | $this->setOption('api.url', 'https://api.github.com'); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Magic method to lazily create API objects |
||
70 | * |
||
71 | * @param string $name Name of property to retrieve |
||
72 | * |
||
73 | * @return Object GitHub API object (gists, issues, pulls, etc). |
||
74 | * |
||
75 | * @since 1.0 |
||
76 | * @throws \InvalidArgumentException If $name is not a valid sub class. |
||
77 | */ |
||
78 | public function __get($name) |
||
79 | { |
||
80 | $class = 'Joomla\\Github\\Package\\' . ucfirst($name); |
||
81 | |||
82 | if (class_exists($class)) |
||
83 | { |
||
84 | View Code Duplication | if (false == isset($this->$name)) |
|
0 ignored issues
–
show
|
|||
85 | { |
||
86 | $this->$name = new $class($this->options, $this->client); |
||
87 | } |
||
88 | |||
89 | return $this->$name; |
||
90 | } |
||
91 | |||
92 | throw new \InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class)); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Get an option from the GitHub instance. |
||
97 | * |
||
98 | * @param string $key The name of the option to get. |
||
99 | * |
||
100 | * @return mixed The option value. |
||
101 | * |
||
102 | * @since 1.0 |
||
103 | */ |
||
104 | public function getOption($key) |
||
105 | { |
||
106 | return isset($this->options[$key]) ? $this->options[$key] : null; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Set an option for the GitHub instance. |
||
111 | * |
||
112 | * @param string $key The name of the option to set. |
||
113 | * @param mixed $value The option value to set. |
||
114 | * |
||
115 | * @return GitHub This object for method chaining. |
||
116 | * |
||
117 | * @since 1.0 |
||
118 | */ |
||
119 | public function setOption($key, $value) |
||
120 | { |
||
121 | $this->options[$key] = $value; |
||
122 | |||
123 | return $this; |
||
124 | } |
||
125 | } |
||
126 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.