Browse Source

Miscellaneous code style changes

Timothy J. Warren 7 months ago
parent
commit
1634e98799

+ 1
- 1
build/CodeIgniter/Sniffs/Files/ByteOrderMarkSniff.php View File

@@ -90,7 +90,7 @@ class ByteOrderMarkSniff implements Sniff
90 90
             $fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
91 91
             if ($fileStartHex === $expectedBomHex) {
92 92
                 $error = "File contains a $bomName byte order mark (BOM).";
93
-                $phpcsFile->addError($error, $stackPtr);
93
+                $phpcsFile->addError($error, $stackPtr, 123);
94 94
                 break;
95 95
             }
96 96
         }

+ 4
- 3
build/CodeIgniter/Sniffs/Strings/DoubleQuoteUsageSniff.php View File

@@ -17,6 +17,7 @@ namespace CodeIgniter\Sniffs\Strings;
17 17
 
18 18
 use PHP_CodeSniffer\Sniffs\Sniff;
19 19
 use PHP_CodeSniffer\Files\File;
20
+use Exception;
20 21
 
21 22
 /**
22 23
  * CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff.
@@ -104,19 +105,19 @@ class VariableUsageSniff implements Sniff
104 105
 						$this->_parseVariable($strTokens, $strPtr);
105 106
 					} catch (Exception $err) {
106 107
 						$error = 'There is no variable, object nor array between curly braces. Please use the escape char for $ or {.';
107
-						$phpcsFile->addError($error, $stackPtr);
108
+						$phpcsFile->addError($error, $stackPtr, 234);
108 109
 					}
109 110
 					$variableFound = TRUE;
110 111
 					if ('}' !== $strTokens[$strPtr]) {
111 112
 						$error = 'There is no matching closing curly brace.';
112
-						$phpcsFile->addError($error, $stackPtr);
113
+						$phpcsFile->addError($error, $stackPtr, 345);
113 114
 					}
114 115
 					// don't move forward, since it will be done in the main loop
115 116
 					// $strPtr++;
116 117
 				} else if (T_VARIABLE === $strToken[0]) {
117 118
 					$variableFound = TRUE;
118 119
 					$error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
119
-					$phpcsFile->addError($error, $stackPtr);
120
+					$phpcsFile->addError($error, $stackPtr, 456);
120 121
 				}
121 122
 			}
122 123
 			$strPtr++;

+ 54
- 55
composer.json View File

@@ -1,58 +1,57 @@
1 1
 {
2
-	"name": "aviat/hummingbird-anime-client",
3
-	"description": "A self-hosted anime/manga client for Kitsu.",
4
-	"license":"MIT",
5
-	"autoload": {
6
-		"files": [
7
-			"src/AnimeClient.php"
8
-		],
9
-		"psr-4": {
10
-			"Aviat\\AnimeClient\\": "src/"
11
-		}
12
-	},
13
-	"autoload-dev": {
14
-		"psr-4": {
15
-			"Aviat\\AnimeClient\\Tests\\": "tests/",
16
-			"CodeIgniter\\": "build/CodeIgniter/"
17
-		}
18
-	},
19
-	"require": {
20
-		"aura/html": "^2.0",
21
-		"aura/router": "^3.0",
22
-		"aura/session": "^2.0",
23
-		"aviat/banker": "^1.0.0",
24
-		"aviat/ion": "^2.2.0",
25
-		"monolog/monolog": "^1.0",
26
-		"psr/http-message": "~1.0",
27
-		"psr/log": "~1.0",
28
-		"yosymfony/toml": "^1.0",
29
-		"zendframework/zend-diactoros": "^1.3",
30
-		"maximebf/consolekit": "^1.0",
31
-		"amphp/artax": "^2.0"
32
-	},
33
-	"require-dev": {
34
-		"pdepend/pdepend": "^2.2",
35
-		"sebastian/phpcpd": "^3.0",
36
-		"theseer/phpdox": "dev-master",
37
-		"phploc/phploc": "^4.0",
38
-		"phpmd/phpmd": "^2.4",
39
-		"phpunit/phpunit": "^6.0",
40
-		"robmorgan/phinx": "^0.9.1",
41
-		"consolidation/robo": "~1.0",
42
-		"henrikbjorn/lurker": "^1.1.0",
43
-		"symfony/var-dumper": "^4.0.1",
44
-		"squizlabs/php_codesniffer": "^3.0.0@beta",
45
-		"phpstan/phpstan": "^0.9.1",
46
-		"spatie/phpunit-snapshot-assertions": "^1.2.0"
47
-	},
48
-	"scripts": {
49
-		"build": "vendor/bin/robo build",
50
-		"build:css": "cd public && npm run build && cd ..",
51
-		"clean": "vendor/bin/robo clean",
52
-		"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
53
-		"docs": "vendor/bin/phpdox",
54
-		"phpstan": "phpstan analyse src tests",
55
-		"watch:css": "cd public && npm run watch",
56
-		"test": "vendor/bin/phpunit"
2
+  "name": "aviat/hummingbird-anime-client",
3
+  "description": "A self-hosted anime/manga client for Kitsu.",
4
+  "license": "MIT",
5
+  "autoload": {
6
+	"files": [
7
+	  "src/AnimeClient.php"
8
+	],
9
+	"psr-4": {
10
+	  "Aviat\\AnimeClient\\": "src/"
57 11
 	}
12
+  },
13
+  "autoload-dev": {
14
+	"psr-4": {
15
+	  "Aviat\\AnimeClient\\Tests\\": "tests/",
16
+	  "CodeIgniter\\": "build/CodeIgniter/"
17
+	}
18
+  },
19
+  "require": {
20
+	"amphp/artax": "^2.0",
21
+	"aura/html": "^2.0",
22
+	"aura/router": "^3.0",
23
+	"aura/session": "^2.0",
24
+	"aviat/banker": "^1.0.0",
25
+	"aviat/ion": "^2.2.0",
26
+	"maximebf/consolekit": "^1.0",
27
+	"monolog/monolog": "^1.0",
28
+	"psr/http-message": "~1.0",
29
+	"psr/log": "~1.0",
30
+	"yosymfony/toml": "^1.0",
31
+	"zendframework/zend-diactoros": "^1.3"
32
+  },
33
+  "require-dev": {
34
+	"consolidation/robo": "~1.0",
35
+	"henrikbjorn/lurker": "^1.1.0",
36
+	"pdepend/pdepend": "^2.2",
37
+	"phploc/phploc": "^4.0",
38
+	"phpmd/phpmd": "^2.4",
39
+	"phpstan/phpstan": "^0.9.1",
40
+	"phpunit/phpunit": "^6.0",
41
+	"robmorgan/phinx": "^0.9.1",
42
+	"sebastian/phpcpd": "^3.0",
43
+	"spatie/phpunit-snapshot-assertions": "^1.2.0",
44
+	"squizlabs/php_codesniffer": "^3.0.0@beta",
45
+	"theseer/phpdox": "^0.10.1"
46
+  },
47
+  "scripts": {
48
+	"build": "vendor/bin/robo build",
49
+	"build:css": "cd public && npm run build && cd ..",
50
+	"clean": "vendor/bin/robo clean",
51
+	"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
52
+	"docs": "vendor/bin/phpdox",
53
+	"phpstan": "phpstan analyse src tests",
54
+	"watch:css": "cd public && npm run watch",
55
+	"test": "vendor/bin/phpunit"
56
+  }
58 57
 }

+ 5
- 7
index.php View File

@@ -16,7 +16,6 @@
16 16
 
17 17
 namespace Aviat\AnimeClient;
18 18
 
19
-use function Aviat\AnimeClient\loadToml;
20 19
 use function Aviat\Ion\_dir;
21 20
 
22 21
 // Work around the silly timezone error
@@ -27,7 +26,7 @@ if ($timezone === '' || $timezone === FALSE)
27 26
 }
28 27
 
29 28
 // Load composer autoloader
30
-require __DIR__ . '/vendor/autoload.php';
29
+require_once __DIR__ . '/vendor/autoload.php';
31 30
 
32 31
 // Define base directories
33 32
 $APP_DIR = _dir(__DIR__, 'app');
@@ -37,8 +36,8 @@ $CONF_DIR = _dir($APP_DIR, 'config');
37 36
 // -----------------------------------------------------------------------------
38 37
 // Dependency Injection setup
39 38
 // -----------------------------------------------------------------------------
40
-require _dir($APPCONF_DIR, 'base_config.php'); // $base_config
41
-$di = require _dir($APP_DIR, 'bootstrap.php');
39
+require_once $APPCONF_DIR . '/base_config.php'; // $base_config
40
+$di = require $APP_DIR . '/bootstrap.php';
42 41
 
43 42
 $config = loadToml($CONF_DIR);
44 43
 $config_array = array_merge($base_config, $config);
@@ -46,10 +45,9 @@ $config_array = array_merge($base_config, $config);
46 45
 $container = $di($config_array);
47 46
 
48 47
 // Unset 'constants'
49
-unset($APP_DIR);
50
-unset($CONF_DIR);
48
+unset($APP_DIR, $APPCONF_DIR);
51 49
 
52 50
 // -----------------------------------------------------------------------------
53 51
 // Dispatch to the current route
54 52
 // -----------------------------------------------------------------------------
55
-$container->get('dispatcher')->__invoke();
53
+$container->get('dispatcher')();

+ 30
- 23
src/AnimeClient.php View File

@@ -18,7 +18,10 @@ namespace Aviat\AnimeClient;
18 18
 
19 19
 use Yosymfony\Toml\Toml;
20 20
 
21
-define('SRC_DIR', realpath(__DIR__));
21
+if ( ! defined('SRC_DIR'))
22
+{
23
+	\define('SRC_DIR', \realpath(__DIR__));
24
+}
22 25
 
23 26
 const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
24 27
 const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Index';
@@ -29,35 +32,39 @@ const NOT_FOUND_METHOD = 'notFound';
29 32
 const ERROR_MESSAGE_METHOD = 'errorPage';
30 33
 const SRC_DIR = SRC_DIR;
31 34
 
32
-/**
33
- * Load configuration options from .toml files
34
- *
35
- * @param string $path - Path to load config
36
- * @return array
37
- */
38
-function loadToml(string $path): array
39
-{
40
-	$output = [];
41
-	$files = glob("{$path}/*.toml");
42 35
 
43
-	foreach ($files as $file)
36
+if ( ! \function_exists('Aviat\AnimeClient\loadToml'))
37
+{
38
+	/**
39
+	 * Load configuration options from .toml files
40
+	 *
41
+	 * @param string $path - Path to load config
42
+	 * @return array
43
+	 */
44
+	function loadToml(string $path): array
44 45
 	{
45
-		$key = str_replace('.toml', '', basename($file));
46
-		$toml = file_get_contents($file);
47
-		$config = Toml::Parse($toml);
46
+		$output = [];
47
+		$files = glob("{$path}/*.toml");
48 48
 
49
-		if ($key === 'config')
49
+		foreach ($files as $file)
50 50
 		{
51
-			foreach($config as $name => $value)
51
+			$key = str_replace('.toml', '', basename($file));
52
+			$toml = file_get_contents($file);
53
+			$config = Toml::parse($toml);
54
+
55
+			if ($key === 'config')
52 56
 			{
53
-				$output[$name] = $value;
57
+				foreach($config as $name => $value)
58
+				{
59
+					$output[$name] = $value;
60
+				}
61
+
62
+				continue;
54 63
 			}
55 64
 
56
-			continue;
65
+			$output[$key] = $config;
57 66
 		}
58 67
 
59
-		$output[$key] = $config;
68
+		return $output;
60 69
 	}
61
-
62
-	return $output;
63
-}
70
+}

+ 35
- 9
src/Controller.php View File

@@ -16,19 +16,17 @@
16 16
 
17 17
 namespace Aviat\AnimeClient;
18 18
 
19
-use const Aviat\AnimeClient\SESSION_SEGMENT;
20
-
21 19
 use function Aviat\Ion\_dir;
22 20
 
23
-use Aviat\AnimeClient\API\JsonAPI;
24 21
 use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
22
+use Aviat\Ion\Exception\DoubleRenderException;
25 23
 use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
26 24
 use InvalidArgumentException;
27 25
 
28 26
 /**
29 27
  * Controller base, defines output methods
30 28
  *
31
- * @property Response object $response
29
+ * @property $response Response object
32 30
  */
33 31
 class Controller {
34 32
 
@@ -96,6 +94,8 @@ class Controller {
96 94
 	 * Constructor
97 95
 	 *
98 96
 	 * @param ContainerInterface $container
97
+	 * @throws \Aviat\Ion\Di\ContainerException
98
+	 * @throws \Aviat\Ion\Di\NotFoundException
99 99
 	 */
100 100
 	public function __construct(ContainerInterface $container)
101 101
 	{
@@ -122,7 +122,7 @@ class Controller {
122 122
 
123 123
 		// Set a 'previous' flash value for better redirects
124 124
 		$serverParams = $this->request->getServerParams();
125
-		if (array_key_exists('HTTP_REFERER', $serverParams))
125
+		if (array_key_exists('HTTP_REFERER', $serverParams) && false === stripos($serverParams['HTTP_REFERER'], 'login'))
126 126
 		{
127 127
 			$this->session->setFlash('previous', $serverParams['HTTP_REFERER']);
128 128
 		}
@@ -146,6 +146,8 @@ class Controller {
146 146
 	 * Set the current url in the session as the target of a future redirect
147 147
 	 *
148 148
 	 * @param string|null $url
149
+	 * @throws \Aviat\Ion\Di\ContainerException
150
+	 * @throws \Aviat\Ion\Di\NotFoundException
149 151
 	 * @return void
150 152
 	 */
151 153
 	public function setSessionRedirect(string $url = NULL)
@@ -159,16 +161,17 @@ class Controller {
159 161
 
160 162
 		$util = $this->container->get('util');
161 163
 		$doubleFormPage = $serverParams['HTTP_REFERER'] === $this->request->getUri();
164
+		$isLoginPage = (bool) strpos($serverParams['HTTP_REFERER'], 'login');
162 165
 
163 166
 		// Don't attempt to set the redirect url if
164 167
 		// the page is one of the form type pages,
165 168
 		// and the previous page is also a form type page_segments
166
-		if ($doubleFormPage)
169
+		if ($doubleFormPage || $isLoginPage)
167 170
 		{
168 171
 			return;
169 172
 		}
170 173
 
171
-		if (is_null($url))
174
+		if (null === $url)
172 175
 		{
173 176
 			$url = $util->isViewPage()
174 177
 				? $this->request->url->get()
@@ -181,6 +184,9 @@ class Controller {
181 184
 	/**
182 185
 	 * Redirect to the url previously set in the  session
183 186
 	 *
187
+	 * @throws InvalidArgumentException
188
+	 * @throws \Aviat\Ion\Di\ContainerException
189
+	 * @throws \Aviat\Ion\Di\NotFoundException
184 190
 	 * @return void
185 191
 	 */
186 192
 	public function sessionRedirect()
@@ -204,6 +210,8 @@ class Controller {
204 210
 	 * @param string $template
205 211
 	 * @param array $data
206 212
 	 * @throws InvalidArgumentException
213
+	 * @throws \Aviat\Ion\Di\ContainerException
214
+	 * @throws \Aviat\Ion\Di\NotFoundException
207 215
 	 * @return string
208 216
 	 */
209 217
 	protected function loadPartial($view, string $template, array $data = [])
@@ -235,6 +243,9 @@ class Controller {
235 243
 	 * @param HtmlView $view
236 244
 	 * @param string $template
237 245
 	 * @param array $data
246
+	 * @throws InvalidArgumentException
247
+	 * @throws \Aviat\Ion\Di\ContainerException
248
+	 * @throws \Aviat\Ion\Di\NotFoundException
238 249
 	 * @return void
239 250
 	 */
240 251
 	protected function renderFullPage($view, string $template, array $data)
@@ -260,6 +271,11 @@ class Controller {
260 271
 	/**
261 272
 	 * 404 action
262 273
 	 *
274
+	 * @param string $title
275
+	 * @param string $message
276
+	 * @throws InvalidArgumentException
277
+	 * @throws \Aviat\Ion\Di\ContainerException
278
+	 * @throws \Aviat\Ion\Di\NotFoundException
263 279
 	 * @return void
264 280
 	 */
265 281
 	public function notFound(
@@ -280,6 +296,9 @@ class Controller {
280 296
 	 * @param string $title
281 297
 	 * @param string $message
282 298
 	 * @param string $long_message
299
+	 * @throws InvalidArgumentException
300
+	 * @throws \Aviat\Ion\Di\ContainerException
301
+	 * @throws \Aviat\Ion\Di\NotFoundException
283 302
 	 * @return void
284 303
 	 */
285 304
 	public function errorPage(int $httpCode, string $title, string $message, string $long_message = "")
@@ -330,7 +349,7 @@ class Controller {
330 349
 	/**
331 350
 	 * Helper for consistent page titles
332 351
 	 *
333
-	 * @param string ...$parts Title segements
352
+	 * @param string[] ...$parts Title segments
334 353
 	 * @return string
335 354
 	 */
336 355
 	public function formatTitle(string ...$parts) : string
@@ -344,6 +363,9 @@ class Controller {
344 363
 	 * @param HtmlView $view
345 364
 	 * @param string $type
346 365
 	 * @param string $message
366
+	 * @throws InvalidArgumentException
367
+	 * @throws \Aviat\Ion\Di\ContainerException
368
+	 * @throws \Aviat\Ion\Di\NotFoundException
347 369
 	 * @return string
348 370
 	 */
349 371
 	protected function showMessage($view, string $type, string $message): string
@@ -361,11 +383,14 @@ class Controller {
361 383
 	 * @param array $data
362 384
 	 * @param HtmlView|null $view
363 385
 	 * @param int $code
386
+	 * @throws InvalidArgumentException
387
+	 * @throws \Aviat\Ion\Di\ContainerException
388
+	 * @throws \Aviat\Ion\Di\NotFoundException
364 389
 	 * @return void
365 390
 	 */
366 391
 	protected function outputHTML(string $template, array $data = [], $view = NULL, int $code = 200)
367 392
 	{
368
-		if (is_null($view))
393
+		if (null === $view)
369 394
 		{
370 395
 			$view = new HtmlView($this->container);
371 396
 		}
@@ -379,6 +404,7 @@ class Controller {
379 404
 	 *
380 405
 	 * @param mixed $data
381 406
 	 * @param int $code - the http status code
407
+	 * @throws DoubleRenderException
382 408
 	 * @return void
383 409
 	 */
384 410
 	protected function outputJSON($data = 'Empty response', int $code = 200)

+ 0
- 2
src/Controller/Manga.php View File

@@ -273,8 +273,6 @@ class Manga extends Controller {
273 273
 			);
274 274
 		}
275 275
 
276
-		// dump($data);
277
-
278 276
 		foreach($data['included'] as $included)
279 277
 		{
280 278
 			if ($included['type'] === 'characters')