@@ -17,9 +17,9 @@ class Contents extends AbstractApi
17
17
* Get content of README file in a repository
18
18
* @link http://developer.github.com/v3/repos/contents/
19
19
*
20
- * @param string $username the user who owns the repository
21
- * @param string $repository the name of the repository
22
- * @param string $reference reference to a branch or commit
20
+ * @param string $username the user who owns the repository
21
+ * @param string $repository the name of the repository
22
+ * @param null| string $reference reference to a branch or commit
23
23
*
24
24
* @return array information for README file
25
25
*/
@@ -34,10 +34,10 @@ public function readme($username, $repository, $reference = null)
34
34
* Get contents of any file or directory in a repository
35
35
* @link http://developer.github.com/v3/repos/contents/
36
36
*
37
- * @param string $username the user who owns the repository
38
- * @param string $repository the name of the repository
39
- * @param string $path path to file or directory
40
- * @param string $reference reference to a branch or commit
37
+ * @param string $username the user who owns the repository
38
+ * @param string $repository the name of the repository
39
+ * @param null| string $path path to file or directory
40
+ * @param null| string $reference reference to a branch or commit
41
41
*
42
42
* @return array information for file | information for each item in directory
43
43
*/
@@ -57,10 +57,10 @@ public function show($username, $repository, $path = null, $reference = null)
57
57
* Get content of archives in a repository
58
58
* @link http://developer.github.com/v3/repos/contents/
59
59
*
60
- * @param string $username the user who owns the repository
61
- * @param string $repository the name of the repository
62
- * @param string $format format of archive: tarball or zipball
63
- * @param string $reference reference to a branch or commit
60
+ * @param string $username the user who owns the repository
61
+ * @param string $repository the name of the repository
62
+ * @param string $format format of archive: tarball or zipball
63
+ * @param null| string $reference reference to a branch or commit
64
64
*
65
65
* @return array information for archives
66
66
*/
@@ -78,20 +78,20 @@ public function archive($username, $repository, $format, $reference = null)
78
78
/**
79
79
* Get the contents of a file in a repository
80
80
*
81
- * @param string $username the user who owns the repository
82
- * @param string $repository the name of the repository
83
- * @param string $path path to file
84
- * @param string $reference reference to a branch or commit
81
+ * @param string $username the user who owns the repository
82
+ * @param string $repository the name of the repository
83
+ * @param string $path path to file
84
+ * @param null| string $reference reference to a branch or commit
85
85
*
86
- * @return string| null content of file, or null in case of base64_decode failure
86
+ * @return null|string content of file, or null in case of base64_decode failure
87
87
*
88
88
* @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64
89
89
* @throws ErrorException If $path doesn't include a 'content' index
90
90
*/
91
91
public function download ($ username , $ repository , $ path , $ reference = null )
92
92
{
93
93
$ file = $ this ->show ($ username , $ repository , $ path , $ reference );
94
-
94
+
95
95
if (!isset ($ file ['type ' ]) || 'file ' !== $ file ['type ' ]) {
96
96
throw new InvalidArgumentException (sprintf ('Path "%s" is not a file. ' , $ path ));
97
97
}
@@ -101,8 +101,10 @@ public function download($username, $repository, $path, $reference = null)
101
101
}
102
102
103
103
if (!isset ($ file ['encoding ' ])) {
104
- throw new InvalidArgumentException (sprintf ('Can\t decode contents of file "%s" as no encoding is defined. ' , $ path ));
105
- } elseif ('base64 ' !== $ file ['encoding ' ]) {
104
+ throw new InvalidArgumentException (sprintf ('Can \'t decode content of file "%s", as no encoding is defined. ' , $ path ));
105
+ }
106
+
107
+ if ('base64 ' !== $ file ['encoding ' ]) {
106
108
throw new InvalidArgumentException (sprintf ('Encoding "%s" of file "%s" is not supported. ' , $ file ['encoding ' ], $ path ));
107
109
}
108
110
0 commit comments