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

AnimeClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 6
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 67
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A is_selected() 0 4 2
A is_not_selected() 0 4 2
A is_view_page() 0 10 1
A is_form_page() 0 4 1
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