@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string|number|StringBuilder_Interface|NULL $content |
| 30 | 30 | * @return HTMLTag |
| 31 | 31 | */ |
| 32 | - public static function anchor(string $url, $content=null) : HTMLTag |
|
| 32 | + public static function anchor(string $url, $content = null) : HTMLTag |
|
| 33 | 33 | { |
| 34 | 34 | return HTMLTag::create('a') |
| 35 | 35 | ->href($url) |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param string|number|StringBuilder_Interface|NULL $content |
| 47 | 47 | * @return HTMLTag |
| 48 | 48 | */ |
| 49 | - public static function div($content=null) : HTMLTag |
|
| 49 | + public static function div($content = null) : HTMLTag |
|
| 50 | 50 | { |
| 51 | 51 | return HTMLTag::create('div')->setContent($content); |
| 52 | 52 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param string|number|StringBuilder_Interface|NULL $content |
| 56 | 56 | * @return HTMLTag |
| 57 | 57 | */ |
| 58 | - public static function p($content=null) : HTMLTag |
|
| 58 | + public static function p($content = null) : HTMLTag |
|
| 59 | 59 | { |
| 60 | 60 | return HTMLTag::create('p')->setContent($content); |
| 61 | 61 | } |
@@ -17,21 +17,20 @@ discard block |
||
| 17 | 17 | * @package Application Utils |
| 18 | 18 | * @subpackage ConvertHelper |
| 19 | 19 | * @author Sebastian Mordziol <[email protected]> |
| 20 | - |
|
| 21 | 20 | * @see ConvertHelper::interval2string() |
| 22 | 21 | */ |
| 23 | 22 | class ConvertHelper_IntervalConverter |
| 24 | 23 | { |
| 25 | 24 | public const ERROR_MISSING_TRANSLATION = 43501; |
| 26 | 25 | |
| 27 | - /** |
|
| 28 | - * @var array<string,string>|NULL |
|
| 29 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var array<string,string>|NULL |
|
| 28 | + */ |
|
| 30 | 29 | protected static $texts = null; |
| 31 | 30 | |
| 32 | - /** |
|
| 33 | - * @var string[] |
|
| 34 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var string[] |
|
| 33 | + */ |
|
| 35 | 34 | protected $tokens = array('y', 'm', 'd', 'h', 'i', 's'); |
| 36 | 35 | |
| 37 | 36 | public function __construct() |
@@ -41,25 +40,25 @@ discard block |
||
| 41 | 40 | } |
| 42 | 41 | } |
| 43 | 42 | |
| 44 | - /** |
|
| 45 | - * Called whenever the application locale has changed, |
|
| 46 | - * to reset the internal translation cache. |
|
| 47 | - */ |
|
| 43 | + /** |
|
| 44 | + * Called whenever the application locale has changed, |
|
| 45 | + * to reset the internal translation cache. |
|
| 46 | + */ |
|
| 48 | 47 | public function handle_localeChanged() : void |
| 49 | 48 | { |
| 50 | 49 | self::$texts = null; |
| 51 | 50 | } |
| 52 | 51 | |
| 53 | - /** |
|
| 54 | - * Converts the specified interval to a human-readable |
|
| 55 | - * string, e.g. "2 hours and 4 minutes". |
|
| 56 | - * |
|
| 57 | - * @param \DateInterval $interval |
|
| 58 | - * @return string |
|
| 59 | - * @throws ConvertHelper_Exception |
|
| 60 | - * |
|
| 61 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
| 62 | - */ |
|
| 52 | + /** |
|
| 53 | + * Converts the specified interval to a human-readable |
|
| 54 | + * string, e.g. "2 hours and 4 minutes". |
|
| 55 | + * |
|
| 56 | + * @param \DateInterval $interval |
|
| 57 | + * @return string |
|
| 58 | + * @throws ConvertHelper_Exception |
|
| 59 | + * |
|
| 60 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
| 61 | + */ |
|
| 63 | 62 | public function toString(\DateInterval $interval) : string |
| 64 | 63 | { |
| 65 | 64 | $this->initTexts(); |
@@ -88,14 +87,14 @@ discard block |
||
| 88 | 87 | return t('%1$s and %2$s', implode(', ', $parts), $last); |
| 89 | 88 | } |
| 90 | 89 | |
| 91 | - /** |
|
| 92 | - * Translates the selected time token, e.g. "y" (for year). |
|
| 93 | - * |
|
| 94 | - * @param string $token |
|
| 95 | - * @param ConvertHelper_DateInterval $interval |
|
| 96 | - * @throws ConvertHelper_Exception |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 90 | + /** |
|
| 91 | + * Translates the selected time token, e.g. "y" (for year). |
|
| 92 | + * |
|
| 93 | + * @param string $token |
|
| 94 | + * @param ConvertHelper_DateInterval $interval |
|
| 95 | + * @throws ConvertHelper_Exception |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 99 | 98 | protected function translateToken(string $token, ConvertHelper_DateInterval $interval) : string |
| 100 | 99 | { |
| 101 | 100 | $value = $interval->getToken($token); |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | ); |
| 124 | 123 | } |
| 125 | 124 | |
| 126 | - /** |
|
| 127 | - * Resolves all time tokens that need to be translated in |
|
| 128 | - * the subject interval, depending on its length. |
|
| 129 | - * |
|
| 130 | - * @param ConvertHelper_DateInterval $interval |
|
| 131 | - * @return string[] |
|
| 132 | - */ |
|
| 125 | + /** |
|
| 126 | + * Resolves all time tokens that need to be translated in |
|
| 127 | + * the subject interval, depending on its length. |
|
| 128 | + * |
|
| 129 | + * @param ConvertHelper_DateInterval $interval |
|
| 130 | + * @return string[] |
|
| 131 | + */ |
|
| 133 | 132 | protected function resolveTokens(ConvertHelper_DateInterval $interval) : array |
| 134 | 133 | { |
| 135 | 134 | $offset = 0; |
@@ -147,9 +146,9 @@ discard block |
||
| 147 | 146 | return array(); |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | - /** |
|
| 151 | - * Initializes the translateable strings. |
|
| 152 | - */ |
|
| 149 | + /** |
|
| 150 | + * Initializes the translateable strings. |
|
| 151 | + */ |
|
| 153 | 152 | protected function initTexts() : void |
| 154 | 153 | { |
| 155 | 154 | if(isset(self::$texts)) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function __construct() |
| 38 | 38 | { |
| 39 | - if(class_exists('\AppLocalize\Localization')) { |
|
| 39 | + if (class_exists('\AppLocalize\Localization')) { |
|
| 40 | 40 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -69,17 +69,17 @@ discard block |
||
| 69 | 69 | $keep = $this->resolveTokens($interval); |
| 70 | 70 | |
| 71 | 71 | $parts = array(); |
| 72 | - foreach($keep as $token) |
|
| 72 | + foreach ($keep as $token) |
|
| 73 | 73 | { |
| 74 | 74 | $value = $interval->getToken($token); |
| 75 | - if($value <= 0) { |
|
| 75 | + if ($value <= 0) { |
|
| 76 | 76 | continue; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $parts[] = $this->translateToken($token, $interval); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(count($parts) == 1) { |
|
| 82 | + if (count($parts) == 1) { |
|
| 83 | 83 | return $parts[0]; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | $value = $interval->getToken($token); |
| 102 | 102 | |
| 103 | 103 | $suffix = 'p'; |
| 104 | - if($value == 1) { $suffix = 's'; } |
|
| 104 | + if ($value == 1) { $suffix = 's'; } |
|
| 105 | 105 | $token .= $suffix; |
| 106 | 106 | |
| 107 | - if(!isset(self::$texts[$token])) |
|
| 107 | + if (!isset(self::$texts[$token])) |
|
| 108 | 108 | { |
| 109 | 109 | throw new ConvertHelper_Exception( |
| 110 | 110 | 'Missing interval translation', |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | $offset = 0; |
| 136 | 136 | |
| 137 | - foreach($this->tokens as $token) |
|
| 137 | + foreach ($this->tokens as $token) |
|
| 138 | 138 | { |
| 139 | - if($interval->getToken($token) > 0) |
|
| 139 | + if ($interval->getToken($token) > 0) |
|
| 140 | 140 | { |
| 141 | 141 | return array_slice($this->tokens, $offset); |
| 142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | protected function initTexts() : void |
| 154 | 154 | { |
| 155 | - if(isset(self::$texts)) { |
|
| 155 | + if (isset(self::$texts)) { |
|
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | public function setAttributes(array $attributes) : AttributeCollection |
| 48 | 48 | { |
| 49 | 49 | // import existing classes |
| 50 | - if(isset($attributes['class'])) |
|
| 50 | + if (isset($attributes['class'])) |
|
| 51 | 51 | { |
| 52 | 52 | $this->addClasses(ConvertHelper::explodeTrim(' ', $attributes['class'])); |
| 53 | 53 | unset($attributes['class']); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - foreach($attributes as $name => $value) |
|
| 56 | + foreach ($attributes as $name => $value) |
|
| 57 | 57 | { |
| 58 | 58 | $this->attr($name, $value); |
| 59 | 59 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | return $this; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function getAttribute(string $name, string $default='') : string |
|
| 64 | + public function getAttribute(string $name, string $default = '') : string |
|
| 65 | 65 | { |
| 66 | 66 | return $this->attributes[$name] ?? $default; |
| 67 | 67 | } |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | * @param array<string,string|number> $attributes |
| 71 | 71 | * @return AttributeCollection |
| 72 | 72 | */ |
| 73 | - public static function create(array $attributes=array()) : AttributeCollection |
|
| 73 | + public static function create(array $attributes = array()) : AttributeCollection |
|
| 74 | 74 | { |
| 75 | 75 | return new AttributeCollection($attributes); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function prop(string $name, bool $enabled=true) : AttributeCollection |
|
| 78 | + public function prop(string $name, bool $enabled = true) : AttributeCollection |
|
| 79 | 79 | { |
| 80 | - if($enabled) |
|
| 80 | + if ($enabled) |
|
| 81 | 81 | { |
| 82 | 82 | return $this->attr($name, $name); |
| 83 | 83 | } |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function attr(string $name, $value) : AttributeCollection |
| 94 | 94 | { |
| 95 | - if($value === true) |
|
| 95 | + if ($value === true) |
|
| 96 | 96 | { |
| 97 | 97 | $string = 'true'; |
| 98 | 98 | } |
| 99 | - else if($value === false) |
|
| 99 | + else if ($value === false) |
|
| 100 | 100 | { |
| 101 | 101 | $string = 'false'; |
| 102 | 102 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $string = (string)$value; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if($string !== '') |
|
| 108 | + if ($string !== '') |
|
| 109 | 109 | { |
| 110 | 110 | $this->attributes[$name] = $string; |
| 111 | 111 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | { |
| 125 | 125 | $this->attr($name, $value); |
| 126 | 126 | |
| 127 | - if(isset($this->attributes[$name])) |
|
| 127 | + if (isset($this->attributes[$name])) |
|
| 128 | 128 | { |
| 129 | 129 | $this->attributes[$name] = Filtering::quotes($this->attributes[$name]); |
| 130 | 130 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | public function remove(string $name) : AttributeCollection |
| 141 | 141 | { |
| 142 | - if(isset($this->attributes[$name])) |
|
| 142 | + if (isset($this->attributes[$name])) |
|
| 143 | 143 | { |
| 144 | 144 | unset($this->attributes[$name]); |
| 145 | 145 | } |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $attributes = $this->attributes; |
| 165 | 165 | |
| 166 | - if($this->hasClasses()) |
|
| 166 | + if ($this->hasClasses()) |
|
| 167 | 167 | { |
| 168 | 168 | $attributes['class'] = $this->classesToString(); |
| 169 | 169 | } |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $attributes = $this->getAttributes(); |
| 179 | 179 | |
| 180 | - if(empty($attributes)) |
|
| 180 | + if (empty($attributes)) |
|
| 181 | 181 | { |
| 182 | 182 | return ''; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - foreach($attributes as $name => $value) |
|
| 185 | + foreach ($attributes as $name => $value) |
|
| 186 | 186 | { |
| 187 | - if($value === '') |
|
| 187 | + if ($value === '') |
|
| 188 | 188 | { |
| 189 | 189 | continue; |
| 190 | 190 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | private function renderAttribute(string $name, string $value) : string |
| 199 | 199 | { |
| 200 | - if($name === $value) |
|
| 200 | + if ($name === $value) |
|
| 201 | 201 | { |
| 202 | 202 | return $name; |
| 203 | 203 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | public const TARGET_BLANK = '_blank'; |
| 242 | 242 | |
| 243 | - public function target(string $value=self::TARGET_BLANK) : AttributeCollection |
|
| 243 | + public function target(string $value = self::TARGET_BLANK) : AttributeCollection |
|
| 244 | 244 | { |
| 245 | 245 | return $this->attr('target', $value); |
| 246 | 246 | } |
@@ -95,12 +95,10 @@ discard block |
||
| 95 | 95 | if($value === true) |
| 96 | 96 | { |
| 97 | 97 | $string = 'true'; |
| 98 | - } |
|
| 99 | - else if($value === false) |
|
| 98 | + } else if($value === false) |
|
| 100 | 99 | { |
| 101 | 100 | $string = 'false'; |
| 102 | - } |
|
| 103 | - else |
|
| 101 | + } else |
|
| 104 | 102 | { |
| 105 | 103 | $string = (string)$value; |
| 106 | 104 | } |
@@ -214,8 +212,7 @@ discard block |
||
| 214 | 212 | try |
| 215 | 213 | { |
| 216 | 214 | return $this->render(); |
| 217 | - } |
|
| 218 | - catch (Throwable $e) |
|
| 215 | + } catch (Throwable $e) |
|
| 219 | 216 | { |
| 220 | 217 | return ''; |
| 221 | 218 | } |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | public const ERROR_FAILED_CONVERTING_TO_JSON = 37901; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var SimpleXMLElement |
|
| 51 | - */ |
|
| 49 | + /** |
|
| 50 | + * @var SimpleXMLElement |
|
| 51 | + */ |
|
| 52 | 52 | protected $xml; |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var string|NULL |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var string|NULL |
|
| 56 | + */ |
|
| 57 | 57 | protected $json; |
| 58 | 58 | |
| 59 | 59 | protected function __construct(SimpleXMLElement $element) |
@@ -86,34 +86,34 @@ discard block |
||
| 86 | 86 | return self::fromElement(new SimpleXMLElement($xmlString)); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Factory method: creates a converter from an existing SimpleXMLElement instance. |
|
| 91 | - * |
|
| 92 | - * @param SimpleXMLElement $element |
|
| 93 | - * @return XMLHelper_Converter |
|
| 94 | - */ |
|
| 89 | + /** |
|
| 90 | + * Factory method: creates a converter from an existing SimpleXMLElement instance. |
|
| 91 | + * |
|
| 92 | + * @param SimpleXMLElement $element |
|
| 93 | + * @return XMLHelper_Converter |
|
| 94 | + */ |
|
| 95 | 95 | public static function fromElement(SimpleXMLElement $element) : XMLHelper_Converter |
| 96 | 96 | { |
| 97 | 97 | return new XMLHelper_Converter($element); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Factory method: creates a converter from an existing SimpleXMLElement instance. |
|
| 102 | - * |
|
| 103 | - * @param DOMElement $element |
|
| 104 | - * @return XMLHelper_Converter |
|
| 105 | - */ |
|
| 100 | + /** |
|
| 101 | + * Factory method: creates a converter from an existing SimpleXMLElement instance. |
|
| 102 | + * |
|
| 103 | + * @param DOMElement $element |
|
| 104 | + * @return XMLHelper_Converter |
|
| 105 | + */ |
|
| 106 | 106 | public static function fromDOMElement(DOMElement $element) : XMLHelper_Converter |
| 107 | 107 | { |
| 108 | 108 | return new XMLHelper_Converter(simplexml_import_dom($element)); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Converts the XML to JSON. |
|
| 113 | - * |
|
| 114 | - * @return string |
|
| 115 | - * @throws XMLHelper_Exception|JsonException |
|
| 116 | - */ |
|
| 111 | + /** |
|
| 112 | + * Converts the XML to JSON. |
|
| 113 | + * |
|
| 114 | + * @return string |
|
| 115 | + * @throws XMLHelper_Exception|JsonException |
|
| 116 | + */ |
|
| 117 | 117 | public function toJSON() : string |
| 118 | 118 | { |
| 119 | 119 | if (isset($this->json)) |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Converts the XML to an associative array. |
|
| 151 | - * @return array |
|
| 152 | - * @throws XMLHelper_Exception|JsonException |
|
| 153 | - */ |
|
| 149 | + /** |
|
| 150 | + * Converts the XML to an associative array. |
|
| 151 | + * @return array |
|
| 152 | + * @throws XMLHelper_Exception|JsonException |
|
| 153 | + */ |
|
| 154 | 154 | public function toArray() : array |
| 155 | 155 | { |
| 156 | 156 | $json = $this->toJSON(); |
@@ -130,8 +130,7 @@ |
||
| 130 | 130 | unset($this->xml); |
| 131 | 131 | |
| 132 | 132 | return $this->json; |
| 133 | - } |
|
| 134 | - catch (Exception $e) |
|
| 133 | + } catch (Exception $e) |
|
| 135 | 134 | { |
| 136 | 135 | throw new XMLHelper_Exception( |
| 137 | 136 | 'Could not convert the XML source to JSON', |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public const REGEX_MD5 = '/^[a-f0-9]{32}$/i'; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - * @see https://en.wikipedia.org/wiki/Email_address#Local-part |
|
| 48 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + * @see https://en.wikipedia.org/wiki/Email_address#Local-part |
|
| 48 | + */ |
|
| 49 | 49 | public const REGEX_EMAIL = '/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i'; |
| 50 | 50 | |
| 51 | 51 | public const REGEX_PHONE = '/\A[+0-9][0-9 +\-()]+\z/m'; |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public const REGEX_IS_HTML = '%<{0,1}[a-z\/][\s\S]*>|<[a-z\/][\s\S]*>{0,1}%i'; |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Hexadecimal color codes. Allows the following formats: |
|
| 102 | - * |
|
| 103 | - * FFFFFF |
|
| 104 | - * FFF |
|
| 105 | - * |
|
| 106 | - * @var string |
|
| 107 | - */ |
|
| 100 | + /** |
|
| 101 | + * Hexadecimal color codes. Allows the following formats: |
|
| 102 | + * |
|
| 103 | + * FFFFFF |
|
| 104 | + * FFF |
|
| 105 | + * |
|
| 106 | + * @var string |
|
| 107 | + */ |
|
| 108 | 108 | public const REGEX_HEX_COLOR_CODE = '/\A(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\z/iU'; |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected $classes = array(); |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The namespace detected in the file, if any. |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 41 | + /** |
|
| 42 | + * The namespace detected in the file, if any. |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $namespace = ''; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string $path The path to the PHP file to parse. |
|
| 49 | - * @throws FileHelper_Exception |
|
| 50 | - * @see FileHelper::findPHPClasses() |
|
| 51 | - */ |
|
| 47 | + /** |
|
| 48 | + * @param string $path The path to the PHP file to parse. |
|
| 49 | + * @throws FileHelper_Exception |
|
| 50 | + * @see FileHelper::findPHPClasses() |
|
| 51 | + */ |
|
| 52 | 52 | public function __construct(string $path) |
| 53 | 53 | { |
| 54 | 54 | $this->path = realpath($path); |
@@ -68,58 +68,58 @@ discard block |
||
| 68 | 68 | $this->parseFile(); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * The name of the namespace of the classes in the file, if any. |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 71 | + /** |
|
| 72 | + * The name of the namespace of the classes in the file, if any. |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | 75 | public function getNamespace() : string |
| 76 | 76 | { |
| 77 | 77 | return $this->namespace; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Whether the file contains a namespace. |
|
| 82 | - * @return bool |
|
| 83 | - */ |
|
| 80 | + /** |
|
| 81 | + * Whether the file contains a namespace. |
|
| 82 | + * @return bool |
|
| 83 | + */ |
|
| 84 | 84 | public function hasNamespace() : bool |
| 85 | 85 | { |
| 86 | 86 | return !empty($this->namespace); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * The absolute path to the file. |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 89 | + /** |
|
| 90 | + * The absolute path to the file. |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | 93 | public function getPath() : string |
| 94 | 94 | { |
| 95 | 95 | return $this->path; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Whether any classes were found in the file. |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 98 | + /** |
|
| 99 | + * Whether any classes were found in the file. |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | 102 | public function hasClasses() : bool |
| 103 | 103 | { |
| 104 | 104 | return !empty($this->classes); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * The names of the classes that were found in the file (with namespace if any). |
|
| 109 | - * @return string[] |
|
| 110 | - */ |
|
| 107 | + /** |
|
| 108 | + * The names of the classes that were found in the file (with namespace if any). |
|
| 109 | + * @return string[] |
|
| 110 | + */ |
|
| 111 | 111 | public function getClassNames() : array |
| 112 | 112 | { |
| 113 | 113 | return array_keys($this->classes); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Retrieves all classes that were detected in the file, |
|
| 118 | - * which can be used to retrieve more information about |
|
| 119 | - * them. |
|
| 120 | - * |
|
| 121 | - * @return FileHelper_PHPClassInfo_Class[] |
|
| 122 | - */ |
|
| 116 | + /** |
|
| 117 | + * Retrieves all classes that were detected in the file, |
|
| 118 | + * which can be used to retrieve more information about |
|
| 119 | + * them. |
|
| 120 | + * |
|
| 121 | + * @return FileHelper_PHPClassInfo_Class[] |
|
| 122 | + */ |
|
| 123 | 123 | public function getClasses() : array |
| 124 | 124 | { |
| 125 | 125 | return array_values($this->classes); |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Strips all whitespace from the string, replacing it with |
|
| 170 | - * regular spaces (newlines, tabs, etc.). |
|
| 171 | - * |
|
| 172 | - * @param string $string |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 168 | + /** |
|
| 169 | + * Strips all whitespace from the string, replacing it with |
|
| 170 | + * regular spaces (newlines, tabs, etc.). |
|
| 171 | + * |
|
| 172 | + * @param string $string |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | 175 | protected function stripWhitespace(string $string) : string |
| 176 | 176 | { |
| 177 | 177 | return preg_replace('/[\s]/', ' ', $string); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | $this->path = realpath($path); |
| 55 | 55 | |
| 56 | - if($this->path === false) |
|
| 56 | + if ($this->path === false) |
|
| 57 | 57 | { |
| 58 | 58 | throw new FileHelper_Exception( |
| 59 | 59 | 'Cannot extract file information: file not found.', |
@@ -131,25 +131,25 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $result = array(); |
| 133 | 133 | preg_match_all('/namespace[\s]+([^;]+);/six', $code, $result, PREG_PATTERN_ORDER); |
| 134 | - if(isset($result[0]) && isset($result[0][0])) { |
|
| 134 | + if (isset($result[0]) && isset($result[0][0])) { |
|
| 135 | 135 | $this->namespace = trim($result[1][0]); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $result = array(); |
| 139 | 139 | preg_match_all('/(abstract|final)[\s]+(class|trait)[\s]+([\sa-z0-9\\\\_,]+){|(class|trait)[\s]+([\sa-z0-9\\\\_,]+){/six', $code, $result, PREG_PATTERN_ORDER); |
| 140 | 140 | |
| 141 | - if(!isset($result[0]) || !isset($result[0][0])) { |
|
| 141 | + if (!isset($result[0]) || !isset($result[0][0])) { |
|
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $indexes = array_keys($result[0]); |
| 146 | 146 | |
| 147 | - foreach($indexes as $idx) |
|
| 147 | + foreach ($indexes as $idx) |
|
| 148 | 148 | { |
| 149 | 149 | $keyword = $result[1][$idx]; |
| 150 | 150 | $declaration = $result[3][$idx]; |
| 151 | 151 | $type = $result[2][$idx]; |
| 152 | - if(empty($keyword)) { |
|
| 152 | + if (empty($keyword)) { |
|
| 153 | 153 | $type = $result[4][$idx]; |
| 154 | 154 | $declaration = $result[5][$idx]; |
| 155 | 155 | } |
@@ -22,44 +22,44 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class FileHelper_PHPClassInfo_Class |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var FileHelper_PHPClassInfo |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var FileHelper_PHPClassInfo |
|
| 27 | + */ |
|
| 28 | 28 | protected $info; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var bool |
|
| 32 | - */ |
|
| 30 | + /** |
|
| 31 | + * @var bool |
|
| 32 | + */ |
|
| 33 | 33 | protected $abstract = false; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var bool |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var bool |
|
| 37 | + */ |
|
| 38 | 38 | protected $final = false; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | 43 | protected $extends = ''; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[] |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string[] |
|
| 47 | + */ |
|
| 48 | 48 | protected $implements = array(); |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | protected $name; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | 58 | protected $declaration; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | 63 | protected $keyword; |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | private $type; |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * @param FileHelper_PHPClassInfo $info The class info instance. |
|
| 72 | - * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
| 73 | - * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
| 74 | - */ |
|
| 71 | + * @param FileHelper_PHPClassInfo $info The class info instance. |
|
| 72 | + * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
| 73 | + * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
| 74 | + */ |
|
| 75 | 75 | public function __construct(FileHelper_PHPClassInfo $info, string $declaration, string $keyword, string $type) |
| 76 | 76 | { |
| 77 | 77 | $this->info = $info; |
@@ -82,31 +82,31 @@ discard block |
||
| 82 | 82 | $this->analyzeCode(); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Check if this class is a subclass of the specified |
|
| 87 | - * class name. |
|
| 88 | - * |
|
| 89 | - * @param string $className |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 85 | + /** |
|
| 86 | + * Check if this class is a subclass of the specified |
|
| 87 | + * class name. |
|
| 88 | + * |
|
| 89 | + * @param string $className |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | 92 | public function isSublassOf(string $className) : bool |
| 93 | 93 | { |
| 94 | 94 | return is_subclass_of($this->getNameNS(), $className); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * The class name without namespace. |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 97 | + /** |
|
| 98 | + * The class name without namespace. |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | 101 | public function getName() : string |
| 102 | 102 | { |
| 103 | 103 | return $this->name; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * The absolute class name with namespace (if any). |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 106 | + /** |
|
| 107 | + * The absolute class name with namespace (if any). |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | 110 | public function getNameNS() : string |
| 111 | 111 | { |
| 112 | 112 | $name = $this->getName(); |
@@ -118,48 +118,48 @@ discard block |
||
| 118 | 118 | return $name; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Whether it is an abstract class. |
|
| 123 | - * @return bool |
|
| 124 | - */ |
|
| 121 | + /** |
|
| 122 | + * Whether it is an abstract class. |
|
| 123 | + * @return bool |
|
| 124 | + */ |
|
| 125 | 125 | public function isAbstract() : bool |
| 126 | 126 | { |
| 127 | 127 | return $this->abstract; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Whether it is a final class. |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 130 | + /** |
|
| 131 | + * Whether it is a final class. |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | 134 | public function isFinal() : bool |
| 135 | 135 | { |
| 136 | 136 | return $this->final; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * The name of the class that this class extends (with namespace, if specified). |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 139 | + /** |
|
| 140 | + * The name of the class that this class extends (with namespace, if specified). |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | 143 | public function getExtends() : string |
| 144 | 144 | { |
| 145 | 145 | return $this->extends; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * A list of interfaces the class implements, if any. |
|
| 150 | - * @return string[] |
|
| 151 | - */ |
|
| 148 | + /** |
|
| 149 | + * A list of interfaces the class implements, if any. |
|
| 150 | + * @return string[] |
|
| 151 | + */ |
|
| 152 | 152 | public function getImplements() : array |
| 153 | 153 | { |
| 154 | 154 | return $this->implements; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * The class declaration string, with normalized spaces and sorted interface names. |
|
| 159 | - * NOTE: does not include the keyword "abstract" or "final". |
|
| 160 | - * |
|
| 161 | - * @return string |
|
| 162 | - */ |
|
| 157 | + /** |
|
| 158 | + * The class declaration string, with normalized spaces and sorted interface names. |
|
| 159 | + * NOTE: does not include the keyword "abstract" or "final". |
|
| 160 | + * |
|
| 161 | + * @return string |
|
| 162 | + */ |
|
| 163 | 163 | public function getDeclaration() : string |
| 164 | 164 | { |
| 165 | 165 | $parts = array(); |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | return implode(' ', $parts); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * The keyword before "class", e.g. "abstract". |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 182 | + /** |
|
| 183 | + * The keyword before "class", e.g. "abstract". |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | 186 | public function getKeyword() : string |
| 187 | 187 | { |
| 188 | 188 | return $this->keyword; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | { |
| 112 | 112 | $name = $this->getName(); |
| 113 | 113 | |
| 114 | - if($this->info->hasNamespace()) { |
|
| 114 | + if ($this->info->hasNamespace()) { |
|
| 115 | 115 | $name = $this->info->getNamespace().'\\'.$this->name; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | $parts[] = $this->type; |
| 167 | 167 | $parts[] = $this->getName(); |
| 168 | 168 | |
| 169 | - if(!empty($this->extends)) { |
|
| 169 | + if (!empty($this->extends)) { |
|
| 170 | 170 | $parts[] = 'extends'; |
| 171 | 171 | $parts[] = $this->extends; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - if(!empty($this->implements)) { |
|
| 174 | + if (!empty($this->implements)) { |
|
| 175 | 175 | $parts[] = 'implements'; |
| 176 | 176 | $parts[] = implode(', ', $this->implements); |
| 177 | 177 | } |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | protected function analyzeCode() : void |
| 197 | 197 | { |
| 198 | - if($this->keyword === 'abstract') { |
|
| 198 | + if ($this->keyword === 'abstract') { |
|
| 199 | 199 | $this->abstract = true; |
| 200 | - } else if($this->keyword === 'final') { |
|
| 200 | + } else if ($this->keyword === 'final') { |
|
| 201 | 201 | $this->final = true; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -214,16 +214,16 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | $tokenName = 'none'; |
| 216 | 216 | |
| 217 | - foreach($parts as $part) |
|
| 217 | + foreach ($parts as $part) |
|
| 218 | 218 | { |
| 219 | 219 | $part = str_replace(',', '', $part); |
| 220 | 220 | $part = trim($part); |
| 221 | - if(empty($part)) { |
|
| 221 | + if (empty($part)) { |
|
| 222 | 222 | continue; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $name = strtolower($part); |
| 226 | - if($name === 'extends' || $name === 'implements') { |
|
| 226 | + if ($name === 'extends' || $name === 'implements') { |
|
| 227 | 227 | $tokenName = $name; |
| 228 | 228 | continue; |
| 229 | 229 | } |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | |
| 234 | 234 | $this->implements = $tokens['implements']; |
| 235 | 235 | |
| 236 | - if(!empty($this->implements)) { |
|
| 236 | + if (!empty($this->implements)) { |
|
| 237 | 237 | usort($this->implements, function(string $a, string $b) { |
| 238 | 238 | return strnatcasecmp($a, $b); |
| 239 | 239 | }); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if(!empty($tokens['extends'])) { |
|
| 242 | + if (!empty($tokens['extends'])) { |
|
| 243 | 243 | $this->extends = $tokens['extends'][0]; |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | public const ERROR_CALLABLE_THREW_ERROR = 99601; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | 43 | protected $separator = ' '; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[] |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string[] |
|
| 47 | + */ |
|
| 48 | 48 | protected $strings = array(); |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | protected $mode = 'html'; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | 58 | protected $noSpace = '§!§'; |
| 59 | 59 | |
| 60 | 60 | public function __construct() |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Adds a subject as a string. Is ignored if empty. |
|
| 67 | - * |
|
| 68 | - * @param string|number|Interface_Stringable|NULL $string |
|
| 69 | - * @return $this |
|
| 70 | - */ |
|
| 65 | + /** |
|
| 66 | + * Adds a subject as a string. Is ignored if empty. |
|
| 67 | + * |
|
| 68 | + * @param string|number|Interface_Stringable|NULL $string |
|
| 69 | + * @return $this |
|
| 70 | + */ |
|
| 71 | 71 | public function add($string) : StringBuilder |
| 72 | 72 | { |
| 73 | 73 | $string = (string)$string; |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | return $this; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Adds a string without appending an automatic space. |
|
| 85 | - * |
|
| 86 | - * @param string|number|Interface_Stringable|NULL $string |
|
| 87 | - * @return $this |
|
| 88 | - */ |
|
| 83 | + /** |
|
| 84 | + * Adds a string without appending an automatic space. |
|
| 85 | + * |
|
| 86 | + * @param string|number|Interface_Stringable|NULL $string |
|
| 87 | + * @return $this |
|
| 88 | + */ |
|
| 89 | 89 | public function nospace($string) : StringBuilder |
| 90 | 90 | { |
| 91 | 91 | $flattened = (string)$string; |
@@ -98,46 +98,46 @@ discard block |
||
| 98 | 98 | return $this; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Adds raw HTML code. Does not add an automatic space. |
|
| 103 | - * |
|
| 104 | - * @param string|number|Interface_Stringable $html |
|
| 105 | - * @return $this |
|
| 106 | - */ |
|
| 101 | + /** |
|
| 102 | + * Adds raw HTML code. Does not add an automatic space. |
|
| 103 | + * |
|
| 104 | + * @param string|number|Interface_Stringable $html |
|
| 105 | + * @return $this |
|
| 106 | + */ |
|
| 107 | 107 | public function html($html) : StringBuilder |
| 108 | 108 | { |
| 109 | 109 | return $this->nospace($html); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Adds an unordered list with the specified items. |
|
| 114 | - * |
|
| 115 | - * @param array<int,string|number|Interface_Stringable> $items |
|
| 116 | - * @return $this |
|
| 117 | - */ |
|
| 112 | + /** |
|
| 113 | + * Adds an unordered list with the specified items. |
|
| 114 | + * |
|
| 115 | + * @param array<int,string|number|Interface_Stringable> $items |
|
| 116 | + * @return $this |
|
| 117 | + */ |
|
| 118 | 118 | public function ul(array $items) : StringBuilder |
| 119 | 119 | { |
| 120 | 120 | return $this->list('ul', $items); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Adds an ordered list with the specified items. |
|
| 125 | - * |
|
| 126 | - * @param array<int,string|number|Interface_Stringable> $items |
|
| 127 | - * @return $this |
|
| 128 | - */ |
|
| 123 | + /** |
|
| 124 | + * Adds an ordered list with the specified items. |
|
| 125 | + * |
|
| 126 | + * @param array<int,string|number|Interface_Stringable> $items |
|
| 127 | + * @return $this |
|
| 128 | + */ |
|
| 129 | 129 | public function ol(array $items) : StringBuilder |
| 130 | 130 | { |
| 131 | 131 | return $this->list('ol', $items); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Creates a list tag with the items list. |
|
| 136 | - * |
|
| 137 | - * @param string $type The list type, `ol` or `ul`. |
|
| 138 | - * @param array<int,string|number|Interface_Stringable> $items |
|
| 139 | - * @return $this |
|
| 140 | - */ |
|
| 134 | + /** |
|
| 135 | + * Creates a list tag with the items list. |
|
| 136 | + * |
|
| 137 | + * @param string $type The list type, `ol` or `ul`. |
|
| 138 | + * @param array<int,string|number|Interface_Stringable> $items |
|
| 139 | + * @return $this |
|
| 140 | + */ |
|
| 141 | 141 | protected function list(string $type, array $items) : StringBuilder |
| 142 | 142 | { |
| 143 | 143 | return $this->html(sprintf( |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | )); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Add a translated string. |
|
| 152 | - * |
|
| 153 | - * @param string $format The native string to translate. |
|
| 154 | - * @param array<int,mixed> $arguments The variables to inject into the translated string, if any. |
|
| 155 | - * @return $this |
|
| 156 | - */ |
|
| 150 | + /** |
|
| 151 | + * Add a translated string. |
|
| 152 | + * |
|
| 153 | + * @param string $format The native string to translate. |
|
| 154 | + * @param array<int,mixed> $arguments The variables to inject into the translated string, if any. |
|
| 155 | + * @return $this |
|
| 156 | + */ |
|
| 157 | 157 | public function t(string $format, ...$arguments) : StringBuilder |
| 158 | 158 | { |
| 159 | 159 | if(!class_exists('\AppLocalize\Localization')) |
@@ -206,36 +206,36 @@ discard block |
||
| 206 | 206 | return $this->add(ConvertHelper::duration2string($since)); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Adds HTML double quotes around the string. |
|
| 211 | - * |
|
| 212 | - * @param string|number|Interface_Stringable $string |
|
| 213 | - * @return $this |
|
| 214 | - */ |
|
| 209 | + /** |
|
| 210 | + * Adds HTML double quotes around the string. |
|
| 211 | + * |
|
| 212 | + * @param string|number|Interface_Stringable $string |
|
| 213 | + * @return $this |
|
| 214 | + */ |
|
| 215 | 215 | public function quote($string) : StringBuilder |
| 216 | 216 | { |
| 217 | 217 | return $this->sf('"%s"', (string)$string); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Adds a text that is meant as a reference to a UI element, |
|
| 222 | - * like a menu item, button, etc. |
|
| 223 | - * |
|
| 224 | - * @param string|number|Interface_Stringable $string |
|
| 225 | - * @return $this |
|
| 226 | - */ |
|
| 220 | + /** |
|
| 221 | + * Adds a text that is meant as a reference to a UI element, |
|
| 222 | + * like a menu item, button, etc. |
|
| 223 | + * |
|
| 224 | + * @param string|number|Interface_Stringable $string |
|
| 225 | + * @return $this |
|
| 226 | + */ |
|
| 227 | 227 | public function reference($string) : StringBuilder |
| 228 | 228 | { |
| 229 | 229 | return $this->sf('"%s"', $string); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Add a string using the `sprintf` method. |
|
| 234 | - * |
|
| 235 | - * @param string $format The format string |
|
| 236 | - * @param string|number|Interface_Stringable ...$arguments The variables to inject |
|
| 237 | - * @return $this |
|
| 238 | - */ |
|
| 232 | + /** |
|
| 233 | + * Add a string using the `sprintf` method. |
|
| 234 | + * |
|
| 235 | + * @param string $format The format string |
|
| 236 | + * @param string|number|Interface_Stringable ...$arguments The variables to inject |
|
| 237 | + * @return $this |
|
| 238 | + */ |
|
| 239 | 239 | public function sf(string $format, ...$arguments) : StringBuilder |
| 240 | 240 | { |
| 241 | 241 | array_unshift($arguments, $format); |
@@ -243,12 +243,12 @@ discard block |
||
| 243 | 243 | return $this->add(sprintf(...$arguments)); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * Adds a bold string. |
|
| 248 | - * |
|
| 249 | - * @param string|number|Interface_Stringable $string |
|
| 250 | - * @return $this |
|
| 251 | - */ |
|
| 246 | + /** |
|
| 247 | + * Adds a bold string. |
|
| 248 | + * |
|
| 249 | + * @param string|number|Interface_Stringable $string |
|
| 250 | + * @return $this |
|
| 251 | + */ |
|
| 252 | 252 | public function bold($string) : StringBuilder |
| 253 | 253 | { |
| 254 | 254 | return $this->sf( |
@@ -257,15 +257,15 @@ discard block |
||
| 257 | 257 | ); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * Adds an HTML `<br>` tag. |
|
| 262 | - * |
|
| 263 | - * Note: for adding a newline character instead, |
|
| 264 | - * use {@see StringBuilder::eol()}. |
|
| 265 | - * |
|
| 266 | - * @return $this |
|
| 267 | - * @see StringBuilder::eol() |
|
| 268 | - */ |
|
| 260 | + /** |
|
| 261 | + * Adds an HTML `<br>` tag. |
|
| 262 | + * |
|
| 263 | + * Note: for adding a newline character instead, |
|
| 264 | + * use {@see StringBuilder::eol()}. |
|
| 265 | + * |
|
| 266 | + * @return $this |
|
| 267 | + * @see StringBuilder::eol() |
|
| 268 | + */ |
|
| 269 | 269 | public function nl() : StringBuilder |
| 270 | 270 | { |
| 271 | 271 | return $this->html('<br>'); |
@@ -282,42 +282,42 @@ discard block |
||
| 282 | 282 | return $this->nospace(PHP_EOL); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Adds the current time, in the format <code>H:i:s</code>. |
|
| 287 | - * |
|
| 288 | - * @return $this |
|
| 289 | - */ |
|
| 285 | + /** |
|
| 286 | + * Adds the current time, in the format <code>H:i:s</code>. |
|
| 287 | + * |
|
| 288 | + * @return $this |
|
| 289 | + */ |
|
| 290 | 290 | public function time() : StringBuilder |
| 291 | 291 | { |
| 292 | 292 | return $this->add(date('H:i:s')); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Adds the "Note:" text. |
|
| 297 | - * |
|
| 298 | - * @return $this |
|
| 299 | - */ |
|
| 295 | + /** |
|
| 296 | + * Adds the "Note:" text. |
|
| 297 | + * |
|
| 298 | + * @return $this |
|
| 299 | + */ |
|
| 300 | 300 | public function note() : StringBuilder |
| 301 | 301 | { |
| 302 | 302 | return $this->t('Note:'); |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Like {@see StringBuilder::note()}, but as bold text. |
|
| 307 | - * |
|
| 308 | - * @return $this |
|
| 309 | - */ |
|
| 305 | + /** |
|
| 306 | + * Like {@see StringBuilder::note()}, but as bold text. |
|
| 307 | + * |
|
| 308 | + * @return $this |
|
| 309 | + */ |
|
| 310 | 310 | public function noteBold() : StringBuilder |
| 311 | 311 | { |
| 312 | 312 | return $this->bold(sb()->note()); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Adds the "Hint:" text. |
|
| 317 | - * |
|
| 318 | - * @return $this |
|
| 319 | - * @see StringBuilder::hintBold() |
|
| 320 | - */ |
|
| 315 | + /** |
|
| 316 | + * Adds the "Hint:" text. |
|
| 317 | + * |
|
| 318 | + * @return $this |
|
| 319 | + * @see StringBuilder::hintBold() |
|
| 320 | + */ |
|
| 321 | 321 | public function hint() : StringBuilder |
| 322 | 322 | { |
| 323 | 323 | return $this->t('Hint:'); |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | return $this->bold(sb()->hint()); |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * Adds two linebreaks. |
|
| 338 | - * |
|
| 339 | - * @param StringBuilder_Interface|string|NULL $content |
|
| 340 | - * @return $this |
|
| 341 | - */ |
|
| 336 | + /** |
|
| 337 | + * Adds two linebreaks. |
|
| 338 | + * |
|
| 339 | + * @param StringBuilder_Interface|string|NULL $content |
|
| 340 | + * @return $this |
|
| 341 | + */ |
|
| 342 | 342 | public function para($content=null) : StringBuilder |
| 343 | 343 | { |
| 344 | 344 | if($content !== null) { |
@@ -390,12 +390,12 @@ discard block |
||
| 390 | 390 | return $this->html(HTMLTag::create('a')->renderClose()); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * Wraps the string in a `code` tag. |
|
| 395 | - * |
|
| 396 | - * @param string|number|Interface_Stringable $string |
|
| 397 | - * @return $this |
|
| 398 | - */ |
|
| 393 | + /** |
|
| 394 | + * Wraps the string in a `code` tag. |
|
| 395 | + * |
|
| 396 | + * @param string|number|Interface_Stringable $string |
|
| 397 | + * @return $this |
|
| 398 | + */ |
|
| 399 | 399 | public function code($string) : StringBuilder |
| 400 | 400 | { |
| 401 | 401 | return $this->sf( |
@@ -404,24 +404,24 @@ discard block |
||
| 404 | 404 | ); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * Wraps the string in a `pre` tag. |
|
| 409 | - * |
|
| 410 | - * @param string|number|Interface_Stringable $string |
|
| 411 | - * @return $this |
|
| 412 | - */ |
|
| 407 | + /** |
|
| 408 | + * Wraps the string in a `pre` tag. |
|
| 409 | + * |
|
| 410 | + * @param string|number|Interface_Stringable $string |
|
| 411 | + * @return $this |
|
| 412 | + */ |
|
| 413 | 413 | public function pre($string) : StringBuilder |
| 414 | 414 | { |
| 415 | 415 | return $this->sf('<pre>%s</pre>', (string)$string); |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - /** |
|
| 419 | - * Wraps the text in a `span` tag with the specified classes. |
|
| 420 | - * |
|
| 421 | - * @param string|number|Interface_Stringable $string |
|
| 422 | - * @param string|string[] $classes |
|
| 423 | - * @return $this |
|
| 424 | - */ |
|
| 418 | + /** |
|
| 419 | + * Wraps the text in a `span` tag with the specified classes. |
|
| 420 | + * |
|
| 421 | + * @param string|number|Interface_Stringable $string |
|
| 422 | + * @param string|string[] $classes |
|
| 423 | + * @return $this |
|
| 424 | + */ |
|
| 425 | 425 | public function spanned($string, $classes) : StringBuilder |
| 426 | 426 | { |
| 427 | 427 | if(!is_array($classes)) |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $string = (string)$string; |
| 74 | 74 | |
| 75 | - if(!empty($string)) |
|
| 75 | + if (!empty($string)) |
|
| 76 | 76 | { |
| 77 | 77 | $this->strings[] = $string; |
| 78 | 78 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | $flattened = (string)$string; |
| 92 | 92 | |
| 93 | - if($flattened !== "") |
|
| 93 | + if ($flattened !== "") |
|
| 94 | 94 | { |
| 95 | 95 | $this->add($this->noSpace.$flattened); |
| 96 | 96 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function t(string $format, ...$arguments) : StringBuilder |
| 158 | 158 | { |
| 159 | - if(!class_exists('\AppLocalize\Localization')) |
|
| 159 | + if (!class_exists('\AppLocalize\Localization')) |
|
| 160 | 160 | { |
| 161 | 161 | array_unshift($arguments, $format); |
| 162 | 162 | return $this->sf(...$arguments); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | unset($context); // Only used by the localization parser. |
| 183 | 183 | |
| 184 | - if(!class_exists('\AppLocalize\Localization')) |
|
| 184 | + if (!class_exists('\AppLocalize\Localization')) |
|
| 185 | 185 | { |
| 186 | 186 | array_unshift($arguments, $format); |
| 187 | 187 | return $this->sf(...$arguments); |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | * @param StringBuilder_Interface|string|NULL $content |
| 340 | 340 | * @return $this |
| 341 | 341 | */ |
| 342 | - public function para($content=null) : StringBuilder |
|
| 342 | + public function para($content = null) : StringBuilder |
|
| 343 | 343 | { |
| 344 | - if($content !== null) { |
|
| 344 | + if ($content !== null) { |
|
| 345 | 345 | return $this->html('<p>')->nospace($content)->html('</p>'); |
| 346 | 346 | } |
| 347 | 347 | |
@@ -357,21 +357,21 @@ discard block |
||
| 357 | 357 | * @param AttributeCollection|null $attributes |
| 358 | 358 | * @return $this |
| 359 | 359 | */ |
| 360 | - public function link(string $label, string $url, bool $newTab=false, ?AttributeCollection $attributes=null) : StringBuilder |
|
| 360 | + public function link(string $label, string $url, bool $newTab = false, ?AttributeCollection $attributes = null) : StringBuilder |
|
| 361 | 361 | { |
| 362 | 362 | return $this->add($this->createLink($label, $url, $newTab, $attributes)); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - private function createLink(string $label, string $url, bool $newTab=false, ?AttributeCollection $attributes=null) : HTMLTag |
|
| 365 | + private function createLink(string $label, string $url, bool $newTab = false, ?AttributeCollection $attributes = null) : HTMLTag |
|
| 366 | 366 | { |
| 367 | - if($attributes === null) |
|
| 367 | + if ($attributes === null) |
|
| 368 | 368 | { |
| 369 | 369 | $attributes = AttributeCollection::create(); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | $attributes->href($url); |
| 373 | 373 | |
| 374 | - if($newTab) |
|
| 374 | + if ($newTab) |
|
| 375 | 375 | { |
| 376 | 376 | $attributes->target(); |
| 377 | 377 | } |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | ->addText($label); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - public function linkOpen(string $url, bool $newTab=false, ?AttributeCollection $attributes=null) : StringBuilder |
|
| 383 | + public function linkOpen(string $url, bool $newTab = false, ?AttributeCollection $attributes = null) : StringBuilder |
|
| 384 | 384 | { |
| 385 | 385 | return $this->html($this->createLink('', $url, $newTab, $attributes)->renderOpen()); |
| 386 | 386 | } |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | public function spanned($string, $classes) : StringBuilder |
| 426 | 426 | { |
| 427 | - if(!is_array($classes)) |
|
| 427 | + if (!is_array($classes)) |
|
| 428 | 428 | { |
| 429 | 429 | $classes = array((string)$classes); |
| 430 | 430 | } |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | */ |
| 451 | 451 | public function ifTrue(bool $condition, $content) : StringBuilder |
| 452 | 452 | { |
| 453 | - if($condition === true) |
|
| 453 | + if ($condition === true) |
|
| 454 | 454 | { |
| 455 | 455 | $this->add($this->renderContent($content)); |
| 456 | 456 | } |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | */ |
| 473 | 473 | public function ifFalse(bool $condition, $string) : StringBuilder |
| 474 | 474 | { |
| 475 | - if($condition === false) |
|
| 475 | + if ($condition === false) |
|
| 476 | 476 | { |
| 477 | 477 | $this->add($this->renderContent($string)); |
| 478 | 478 | } |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | */ |
| 557 | 557 | public function ifOr(bool $condition, $ifTrue, $ifFalse) : StringBuilder |
| 558 | 558 | { |
| 559 | - if($condition === true) |
|
| 559 | + if ($condition === true) |
|
| 560 | 560 | { |
| 561 | 561 | return $this->add($this->renderContent($ifTrue)); |
| 562 | 562 | } |
@@ -500,8 +500,7 @@ |
||
| 500 | 500 | try |
| 501 | 501 | { |
| 502 | 502 | return $content(); |
| 503 | - } |
|
| 504 | - catch (Exception $e) |
|
| 503 | + } catch (Exception $e) |
|
| 505 | 504 | { |
| 506 | 505 | throw new StringBuilder_Exception( |
| 507 | 506 | 'The callable has thrown an error.', |