Completed
Push — master ( fa4940...275b0e )
by Timothy
02:36
created

AnimeClient::json_file_decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/**
3
 * Hummingbird Anime Client
4
 *
5
 * An API client for Hummingbird to manage anime and manga watch lists
6
 *
7
 * @package     HummingbirdAnimeClient
8
 * @author      Timothy J. Warren
9
 * @copyright   Copyright (c) 2015 - 2016
10
 * @link        https://github.com/timw4mail/HummingBirdAnimeClient
11
 * @license     MIT
12
 */
13
14
namespace Aviat\AnimeClient;
15
16
define('SRC_DIR', realpath(__DIR__ . '/../../'));
17
18
/**
19
 * Odds and Ends class
20
 */
21
class AnimeClient {
22
23
	use \Aviat\Ion\Di\ContainerAware;
24
25
	const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
26
	const DEFAULT_CONTROLLER_NAMESPACE = 'Aviat\AnimeClient\Controller';
27
	const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Anime';
28
	const DEFAULT_CONTROLLER_METHOD = 'index';
29
	const NOT_FOUND_METHOD = 'not_found';
30
	const ERROR_MESSAGE_METHOD = 'error_page';
31
	const SRC_DIR = SRC_DIR;
32
33
	private static $form_pages = [
34
		'edit',
35
		'add',
36
		'update',
37
		'update_form',
38
		'login',
39
		'logout'
40
	];
41
42
	/**
43
	 * HTML selection helper function
44
	 *
45
	 * @param string $a - First item to compare
46
	 * @param string $b - Second item to compare
47
	 * @return string
48
	 */
49
	public static function is_selected($a, $b)
50
	{
51
		return ($a === $b) ? 'selected' : '';
52
	}
53
54
	/**
55
	 * Inverse of selected helper function
56
	 *
57
	 * @param string $a - First item to compare
58
	 * @param string $b - Second item to compare
59
	 * @return string
60
	 */
61
	public static function is_not_selected($a, $b)
62
	{
63
		return ($a !== $b) ? 'selected' : '';
64
	}
65
66
	/**
67
	 * Determine whether to show the sub-menu
68
	 *
69
	 * @return bool
70
	 */
71
	public function is_view_page()
72
	{
73
		$url = $this->container->get('request')
74
			->url->get();
75
		$page_segments = explode("/", $url);
76
77
		$intersect = array_intersect($page_segments, self::$form_pages);
78
79
		return empty($intersect);
80
	}
81
82
	/**
83
	 * Determine whether the page is a page with a form, and
84
	 * not suitable for redirection
85
	 *
86
	 * @return boolean
87
	 */
88
	public function is_form_page()
89
	{
90
		return ! $this->is_view_page();
91
	}
92
93
}
94
// End of anime_client.php