@@ -19,14 +19,14 @@ |
||
19 | 19 | * {@inheritdoc} |
20 | 20 | */ |
21 | 21 | public function getFilters(){ |
22 | - return array( |
|
23 | - new \Twig_SimpleFilter($this->filterPrefix . 'Avatar', array($this, 'avatar'), $this->filterOptions), |
|
24 | - new \Twig_SimpleFilter($this->filterPrefix . 'Https', array($this, 'https'), $this->filterOptions), |
|
25 | - new \Twig_SimpleFilter($this->filterPrefix . 'Size', array($this, 'size'), $this->filterOptions), |
|
26 | - new \Twig_SimpleFilter($this->filterPrefix . 'Default', array($this, 'def'), $this->filterOptions), |
|
27 | - new \Twig_SimpleFilter($this->filterPrefix . 'Rating', array($this, 'rating'), $this->filterOptions) |
|
28 | - ); |
|
29 | - } |
|
22 | + return array( |
|
23 | + new \Twig_SimpleFilter($this->filterPrefix . 'Avatar', array($this, 'avatar'), $this->filterOptions), |
|
24 | + new \Twig_SimpleFilter($this->filterPrefix . 'Https', array($this, 'https'), $this->filterOptions), |
|
25 | + new \Twig_SimpleFilter($this->filterPrefix . 'Size', array($this, 'size'), $this->filterOptions), |
|
26 | + new \Twig_SimpleFilter($this->filterPrefix . 'Default', array($this, 'def'), $this->filterOptions), |
|
27 | + new \Twig_SimpleFilter($this->filterPrefix . 'Rating', array($this, 'rating'), $this->filterOptions) |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Get a Gravatar Avatar URL |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * {@inheritdoc} |
20 | 20 | */ |
21 | - public function getFilters(){ |
|
21 | + public function getFilters() { |
|
22 | 22 | return array( |
23 | - new \Twig_SimpleFilter($this->filterPrefix . 'Avatar', array($this, 'avatar'), $this->filterOptions), |
|
24 | - new \Twig_SimpleFilter($this->filterPrefix . 'Https', array($this, 'https'), $this->filterOptions), |
|
25 | - new \Twig_SimpleFilter($this->filterPrefix . 'Size', array($this, 'size'), $this->filterOptions), |
|
26 | - new \Twig_SimpleFilter($this->filterPrefix . 'Default', array($this, 'def'), $this->filterOptions), |
|
27 | - new \Twig_SimpleFilter($this->filterPrefix . 'Rating', array($this, 'rating'), $this->filterOptions) |
|
23 | + new \Twig_SimpleFilter($this->filterPrefix.'Avatar', array($this, 'avatar'), $this->filterOptions), |
|
24 | + new \Twig_SimpleFilter($this->filterPrefix.'Https', array($this, 'https'), $this->filterOptions), |
|
25 | + new \Twig_SimpleFilter($this->filterPrefix.'Size', array($this, 'size'), $this->filterOptions), |
|
26 | + new \Twig_SimpleFilter($this->filterPrefix.'Default', array($this, 'def'), $this->filterOptions), |
|
27 | + new \Twig_SimpleFilter($this->filterPrefix.'Rating', array($this, 'rating'), $this->filterOptions) |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function avatar($email) { |
38 | 38 | if (filter_var($email, FILTER_VALIDATE_EMAIL)) { |
39 | - return $this->baseUrl . "avatar/" . $this->generateHash($email); |
|
39 | + return $this->baseUrl."avatar/".$this->generateHash($email); |
|
40 | 40 | } else { |
41 | 41 | throw new InvalidArgumentException("The avatar filter must be passed a valid Email address"); |
42 | 42 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | private function query($string, array $addition) { |
138 | 138 | foreach ($addition as $name => $value) { |
139 | - $string .= (strpos($string, "?") === FALSE ? "?" : "&") . $name . "=" . $value; |
|
139 | + $string .= (strpos($string, "?") === FALSE ? "?" : "&").$name."=".$value; |
|
140 | 140 | } |
141 | 141 | return $string; |
142 | 142 | } |
@@ -51,8 +51,7 @@ discard block |
||
51 | 51 | public function https($value) { |
52 | 52 | if (strpos($value, $this->baseUrl) === false) { |
53 | 53 | throw new InvalidArgumentException("You can only convert existing Gravatar URLs to HTTPS"); |
54 | - } |
|
55 | - else { |
|
54 | + } else { |
|
56 | 55 | return str_replace($this->baseUrl, $this->httpsUrl, $value); |
57 | 56 | } |
58 | 57 | } |
@@ -66,12 +65,10 @@ discard block |
||
66 | 65 | public function size($value, $px = 100) { |
67 | 66 | if (!is_numeric($px) || $px < 0 || $px > 2048) { |
68 | 67 | throw new InvalidArgumentException("You must pass the size filter a valid number between 0 and 2048"); |
69 | - } |
|
70 | - else if (strpos($value, $this->baseUrl) === false |
|
68 | + } else if (strpos($value, $this->baseUrl) === false |
|
71 | 69 | && strpos($value, $this->httpsUrl) === false) { |
72 | 70 | throw new InvalidArgumentException("You must pass the size filter an existing Gravatar URL"); |
73 | - } |
|
74 | - else { |
|
71 | + } else { |
|
75 | 72 | return $this->query($value, array("size" => $px)); |
76 | 73 | } |
77 | 74 | } |
@@ -86,15 +83,14 @@ discard block |
||
86 | 83 | public function def($value, $default = "mm", $force = false) { |
87 | 84 | if (strpos($value, $this->baseUrl) === false && strpos($value, $this->httpsUrl) === false) { |
88 | 85 | throw new InvalidArgumentException("You can only a default to existing Gravatar URLs"); |
89 | - } |
|
90 | - else if (!filter_var($default, FILTER_VALIDATE_URL) && !in_array($default, $this->defaults)) { |
|
86 | + } else if (!filter_var($default, FILTER_VALIDATE_URL) && !in_array($default, $this->defaults)) { |
|
91 | 87 | throw new InvalidArgumentException("Default must be a URL or valid default"); |
92 | - } |
|
93 | - else if (!is_bool($force)) { |
|
88 | + } else if (!is_bool($force)) { |
|
94 | 89 | throw new InvalidArgumentException("The force option for a default must be boolean"); |
95 | - } |
|
96 | - else { |
|
97 | - if (filter_var($default, FILTER_VALIDATE_URL)) $default = urlencode($default); |
|
90 | + } else { |
|
91 | + if (filter_var($default, FILTER_VALIDATE_URL)) { |
|
92 | + $default = urlencode($default); |
|
93 | + } |
|
98 | 94 | $force = ($force ? "y" : "n"); |
99 | 95 | return $this->query($value, array("default" => $default, "forcedefault" => $force)); |
100 | 96 | } |
@@ -109,11 +105,9 @@ discard block |
||
109 | 105 | public function rating($value, $rating = "g") { |
110 | 106 | if (strpos($value, $this->baseUrl) === false && strpos($value, $this->httpsUrl) === false) { |
111 | 107 | throw new InvalidArgumentException("You can only add a rating to an existing Gravatar URL"); |
112 | - } |
|
113 | - else if (!in_array(strtolower($rating), $this->ratings)) { |
|
108 | + } else if (!in_array(strtolower($rating), $this->ratings)) { |
|
114 | 109 | throw new InvalidArgumentException("Rating must be g,pg,r or x"); |
115 | - } |
|
116 | - else { |
|
110 | + } else { |
|
117 | 111 | return $this->query($value, array("rating" => $rating)); |
118 | 112 | } |
119 | 113 | } |