@@ -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,14 +11,20 @@ |
||
| 11 | 11 | |
| 12 | 12 | public function match($name, $args, \DomElement $element) { |
| 13 | 13 | |
| 14 | - if ($name !== 'nth-child') return true; |
|
| 14 | + if ($name !== 'nth-child') { |
|
| 15 | + return true; |
|
| 16 | + } |
|
| 15 | 17 | |
| 16 | 18 | $this->count++; |
| 17 | 19 | $criteria = $args[0]; |
| 18 | 20 | |
| 19 | - if (is_callable([$this, $criteria])) return $this->$criteria($this->count); |
|
| 20 | - else if (!is_numeric($criteria)) throw new \Exception("Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
|
| 21 | - else return $this->count == $criteria; |
|
| 21 | + if (is_callable([$this, $criteria])) { |
|
| 22 | + return $this->$criteria($this->count); |
|
| 23 | + } else if (!is_numeric($criteria)) { |
|
| 24 | + throw new \Exception("Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
|
| 25 | + } else { |
|
| 26 | + return $this->count == $criteria; |
|
| 27 | + } |
|
| 22 | 28 | } |
| 23 | 29 | |
| 24 | 30 | private function odd($num) { |