@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function format($value, $rules) { |
17 | - if (!isset($rules['format'])) return $value; |
|
17 | + if (!isset($rules['format'])) { |
|
18 | + return $value; |
|
19 | + } |
|
18 | 20 | $tokens = $rules['format']; |
19 | 21 | |
20 | 22 | $functionName = $tokens->from(\Transphporm\Parser\Tokenizer::NAME, true)->read(); |
@@ -27,8 +29,7 @@ discard block |
||
27 | 29 | |
28 | 30 | try { |
29 | 31 | return $this->processFormat($options, $functionName, $value); |
30 | - } |
|
31 | - catch (\Exception $e) { |
|
32 | + } catch (\Exception $e) { |
|
32 | 33 | throw new \Transphporm\RunException(\Transphporm\Exception::FORMATTER, $functionName, $e); |
33 | 34 | } |
34 | 35 | } |
@@ -43,7 +44,9 @@ discard block |
||
43 | 44 | } |
44 | 45 | } |
45 | 46 | } |
46 | - if (!$functionExists) throw new \Exception("Formatter '$functionName' does not exist"); |
|
47 | + if (!$functionExists) { |
|
48 | + throw new \Exception("Formatter '$functionName' does not exist"); |
|
49 | + } |
|
47 | 50 | return $value; |
48 | 51 | } |
49 | 52 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function run(\DomElement $element) { |
32 | 32 | $this->functionSet->setElement($element); |
33 | - if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
33 | + if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)).DIRECTORY_SEPARATOR; |
|
34 | 34 | $this->configLine = $this->line; |
35 | 35 | try { |
36 | 36 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
@@ -30,11 +30,15 @@ discard block |
||
30 | 30 | |
31 | 31 | public function run(\DomElement $element) { |
32 | 32 | $this->functionSet->setElement($element); |
33 | - if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
33 | + if ($this->file !== null) { |
|
34 | + $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
35 | + } |
|
34 | 36 | $this->configLine = $this->line; |
35 | 37 | try { |
36 | 38 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
37 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
39 | + if (!$this->pseudoMatcher->matches($element)) { |
|
40 | + return; |
|
41 | + } |
|
38 | 42 | |
39 | 43 | // TODO: Have all rule values parsed before running them so that things like `content-append` are not expecting tokens |
40 | 44 | // problem with this is that anything in data changed by run properties is not shown |
@@ -42,10 +46,11 @@ discard block |
||
42 | 46 | |
43 | 47 | foreach ($this->rules as $name => $value) { |
44 | 48 | $result = $this->callProperty($name, $element, $this->getArgs($value)); |
45 | - if ($result === false) break; |
|
49 | + if ($result === false) { |
|
50 | + break; |
|
51 | + } |
|
46 | 52 | } |
47 | - } |
|
48 | - catch (\Transphporm\RunException $e) { |
|
53 | + } catch (\Transphporm\RunException $e) { |
|
49 | 54 | throw new \Transphporm\Exception($e, $this->file, $this->line); |
50 | 55 | } |
51 | 56 | } |
@@ -62,9 +67,10 @@ discard block |
||
62 | 67 | if (isset($this->properties[$name])) { |
63 | 68 | try { |
64 | 69 | return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
65 | - } |
|
66 | - catch (\Exception $e) { |
|
67 | - if ($e instanceof \Transphporm\RunException) throw $e; |
|
70 | + } catch (\Exception $e) { |
|
71 | + if ($e instanceof \Transphporm\RunException) { |
|
72 | + throw $e; |
|
73 | + } |
|
68 | 74 | throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e); |
69 | 75 | } |
70 | 76 | } |
@@ -11,20 +11,28 @@ |
||
11 | 11 | private $lastParentNode; |
12 | 12 | |
13 | 13 | public function match($name, $args, \DomElement $element) { |
14 | - if ($element->parentNode !== $this->lastParentNode) $this->count = 0; |
|
14 | + if ($element->parentNode !== $this->lastParentNode) { |
|
15 | + $this->count = 0; |
|
16 | + } |
|
15 | 17 | |
16 | 18 | $this->lastParentNode = $element->parentNode; |
17 | 19 | |
18 | 20 | |
19 | 21 | |
20 | - if ($name !== 'nth-child') return true; |
|
22 | + if ($name !== 'nth-child') { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $this->count++; |
23 | 27 | $criteria = $args[0]; |
24 | 28 | |
25 | - if (is_callable([$this, $criteria])) return $this->$criteria($this->count); |
|
26 | - else if (!is_numeric($criteria)) throw new \Exception("Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
|
27 | - else return $this->count == $criteria; |
|
29 | + if (is_callable([$this, $criteria])) { |
|
30 | + return $this->$criteria($this->count); |
|
31 | + } else if (!is_numeric($criteria)) { |
|
32 | + throw new \Exception("Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
|
33 | + } else { |
|
34 | + return $this->count == $criteria; |
|
35 | + } |
|
28 | 36 | } |
29 | 37 | |
30 | 38 | private function odd($num) { |