Completed
Push — master ( 125148...6e4e8e )
by Timothy
16:08
created

AnimeClient::is_form_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
10
 * @link        https://github.com/timw4mail/HummingBirdAnimeClient
11
 * @license     MIT
12
 */
13
14
namespace Aviat\AnimeClient;
15
16
class AnimeClient {
17
18
	use \Aviat\Ion\Di\ContainerAware;
19
20
	const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
21
22
	private static $form_pages = [
23
		'edit',
24
		'add',
25
		'update',
26
		'update_form',
27
		'login',
28
		'logout'
29
	];
30
31
	/**
32
	 * HTML selection helper function
33
	 *
34
	 * @param string $a - First item to compare
35
	 * @param string $b - Second item to compare
36
	 * @return string
37
	 */
38
	public static function is_selected($a, $b)
39
	{
40
		return ($a === $b) ? 'selected' : '';
41
	}
42
43
	/**
44
	 * Inverse of selected helper function
45
	 *
46
	 * @param string $a - First item to compare
47
	 * @param string $b - Second item to compare
48
	 * @return string
49
	 */
50
	public static function is_not_selected($a, $b)
51
	{
52
		return ($a !== $b) ? 'selected' : '';
53
	}
54
55
	/**
56
	 * Determine whether to show the sub-menu
57
	 *
58
	 * @return bool
59
	 */
60
	public function is_view_page()
61
	{
62
		$url = $this->container->get('request')
63
			->url->get();
64
		$page_segments = explode("/", $url);
65
66
		$intersect = array_intersect($page_segments, self::$form_pages);
67
68
		return empty($intersect);
69
	}
70
71
	/**
72
	 * Determine whether the page is a page with a form, and
73
	 * not suitable for redirection
74
	 *
75
	 * @return boolean
76
	 */
77
	public function is_form_page()
78
	{
79
		return ! $this->is_view_page();
80
	}
81
82
}
83
// End of anime_client.php