| @@ -7,11 +7,11 @@ | ||
| 7 | 7 |  { | 
| 8 | 8 | public function trans($id, array $parameters = [], $domain = 'messages', $locale = null) | 
| 9 | 9 |      { | 
| 10 | -        return $this->get('vojtasvoboda.twigextensions::lang.' . $id, $parameters, $locale); | |
| 10 | +        return $this->get('vojtasvoboda.twigextensions::lang.'.$id, $parameters, $locale); | |
| 11 | 11 | } | 
| 12 | 12 | |
| 13 | 13 | public function transChoice($id, $number, array $parameters = [], $domain = 'messages', $locale = null) | 
| 14 | 14 |      { | 
| 15 | -        return $this->choice('vojtasvoboda.twigextensions::lang.' . $id, $number, $parameters, $locale); | |
| 15 | +        return $this->choice('vojtasvoboda.twigextensions::lang.'.$id, $number, $parameters, $locale); | |
| 16 | 16 | } | 
| 17 | 17 | } | 
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php namespace VojtaSvoboda\TwigExtensions\Classes; | 
| 2 | 2 | |
| 3 | -use App; | |
| 4 | 3 | use October\Rain\Translation\Translator; | 
| 5 | 4 | use Symfony\Component\Translation\TranslatorInterface; | 
| 6 | 5 | |
| @@ -1,7 +1,5 @@ | ||
| 1 | 1 | <?php namespace VojtaSvoboda\TwigExtensions; | 
| 2 | 2 | |
| 3 | -use App; | |
| 4 | -use Backend; | |
| 5 | 3 | use Carbon\Carbon; | 
| 6 | 4 | use Snilius\Twig\SortByFieldExtension; | 
| 7 | 5 | use System\Classes\PluginBase; | 
| @@ -42,7 +42,7 @@ discard block | ||
| 42 | 42 | |
| 43 | 43 | public function boot() | 
| 44 | 44 |      { | 
| 45 | -        $this->app->singleton('time_diff_translator', function ($app) { | |
| 45 | +        $this->app->singleton('time_diff_translator', function($app) { | |
| 46 | 46 |              $loader = $app->make('translation.loader'); | 
| 47 | 47 |              $locale = $app->config->get('app.locale'); | 
| 48 | 48 | $translator = $app->make(TimeDiffTranslator::class, [$loader, $locale]); | 
| @@ -130,7 +130,7 @@ discard block | ||
| 130 | 130 | $stringLoaderFunc = $stringLoader->getFunctions(); | 
| 131 | 131 | |
| 132 | 132 | return [ | 
| 133 | -            'template_from_string' => function ($template) use ($twig, $stringLoaderFunc) { | |
| 133 | +            'template_from_string' => function($template) use ($twig, $stringLoaderFunc) { | |
| 134 | 134 | $callable = $stringLoaderFunc[0]->getCallable(); | 
| 135 | 135 | return $callable($twig, $template); | 
| 136 | 136 | } | 
| @@ -150,11 +150,11 @@ discard block | ||
| 150 | 150 | $textFilters = $textExtension->getFilters(); | 
| 151 | 151 | |
| 152 | 152 | return [ | 
| 153 | -            'truncate' => function ($value, $length = 30, $preserve = false, $separator = '...') use ($twig, $textFilters) { | |
| 153 | +            'truncate' => function($value, $length = 30, $preserve = false, $separator = '...') use ($twig, $textFilters) { | |
| 154 | 154 | $callable = $textFilters[0]->getCallable(); | 
| 155 | 155 | return $callable($twig, $value, $length, $preserve, $separator); | 
| 156 | 156 | }, | 
| 157 | -            'wordwrap' => function ($value, $length = 80, $separator = "\n", $preserve = false) use ($twig, $textFilters) { | |
| 157 | +            'wordwrap' => function($value, $length = 80, $separator = "\n", $preserve = false) use ($twig, $textFilters) { | |
| 158 | 158 | $callable = $textFilters[1]->getCallable(); | 
| 159 | 159 | return $callable($twig, $value, $length, $separator, $preserve); | 
| 160 | 160 | } | 
| @@ -174,15 +174,15 @@ discard block | ||
| 174 | 174 | $intlFilters = $intlExtension->getFilters(); | 
| 175 | 175 | |
| 176 | 176 | return [ | 
| 177 | -            'localizeddate' => function ($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) use ($twig, $intlFilters) { | |
| 177 | +            'localizeddate' => function($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) use ($twig, $intlFilters) { | |
| 178 | 178 | $callable = $intlFilters[0]->getCallable(); | 
| 179 | 179 | return $callable($twig, $date, $dateFormat, $timeFormat, $locale, $timezone, $format); | 
| 180 | 180 | }, | 
| 181 | -            'localizednumber' => function ($number, $style = 'decimal', $type = 'default', $locale = null) use ($twig, $intlFilters) { | |
| 181 | +            'localizednumber' => function($number, $style = 'decimal', $type = 'default', $locale = null) use ($twig, $intlFilters) { | |
| 182 | 182 | $callable = $intlFilters[1]->getCallable(); | 
| 183 | 183 | return $callable($number, $style, $type, $locale); | 
| 184 | 184 | }, | 
| 185 | -            'localizedcurrency' => function ($number, $currency = null, $locale = null) use ($twig, $intlFilters) { | |
| 185 | +            'localizedcurrency' => function($number, $currency = null, $locale = null) use ($twig, $intlFilters) { | |
| 186 | 186 | $callable = $intlFilters[2]->getCallable(); | 
| 187 | 187 | return $callable($number, $currency, $locale); | 
| 188 | 188 | } | 
| @@ -200,7 +200,7 @@ discard block | ||
| 200 | 200 | $arrayFilters = $arrayExtension->getFilters(); | 
| 201 | 201 | |
| 202 | 202 | return [ | 
| 203 | -            'shuffle' => function ($array) use ($arrayFilters) { | |
| 203 | +            'shuffle' => function($array) use ($arrayFilters) { | |
| 204 | 204 | $callable = $arrayFilters[0]->getCallable(); | 
| 205 | 205 | return $callable($array); | 
| 206 | 206 | } | 
| @@ -221,7 +221,7 @@ discard block | ||
| 221 | 221 | $timeFilters = $timeExtension->getFilters(); | 
| 222 | 222 | |
| 223 | 223 | return [ | 
| 224 | -            'time_diff' => function ($date, $now = null) use ($twig, $timeFilters) { | |
| 224 | +            'time_diff' => function($date, $now = null) use ($twig, $timeFilters) { | |
| 225 | 225 | $callable = $timeFilters[0]->getCallable(); | 
| 226 | 226 | return $callable($twig, $date, $now); | 
| 227 | 227 | } | 
| @@ -239,7 +239,7 @@ discard block | ||
| 239 | 239 | $filters = $extension->getFilters(); | 
| 240 | 240 | |
| 241 | 241 | return [ | 
| 242 | -            'sortbyfield' => function ($array, $sort_by = null, $direction = 'asc') use ($filters) { | |
| 242 | +            'sortbyfield' => function($array, $sort_by = null, $direction = 'asc') use ($filters) { | |
| 243 | 243 | $callable = $filters[0]->getCallable(); | 
| 244 | 244 | return $callable($array, $sort_by, $direction); | 
| 245 | 245 | } | 
| @@ -254,7 +254,7 @@ discard block | ||
| 254 | 254 | private function getMailFilters() | 
| 255 | 255 |      { | 
| 256 | 256 | return [ | 
| 257 | -            'mailto' => function ($string, $link = true, $protected = true, $text = null) { | |
| 257 | +            'mailto' => function($string, $link = true, $protected = true, $text = null) { | |
| 258 | 258 | return $this->hideEmail($string, $link, $protected, $text); | 
| 259 | 259 | } | 
| 260 | 260 | ]; | 
| @@ -268,50 +268,50 @@ discard block | ||
| 268 | 268 | private function getPhpFunctions() | 
| 269 | 269 |      { | 
| 270 | 270 | return [ | 
| 271 | -            'strftime' => function ($time, $format = '%d.%m.%Y %H:%M:%S') { | |
| 271 | +            'strftime' => function($time, $format = '%d.%m.%Y %H:%M:%S') { | |
| 272 | 272 | $timeObj = new Carbon($time); | 
| 273 | 273 | return strftime($format, $timeObj->getTimestamp()); | 
| 274 | 274 | }, | 
| 275 | -            'uppercase' => function ($string) { | |
| 275 | +            'uppercase' => function($string) { | |
| 276 | 276 | return mb_convert_case($string, MB_CASE_UPPER, "UTF-8"); | 
| 277 | 277 | }, | 
| 278 | -            'lowercase' => function ($string) { | |
| 278 | +            'lowercase' => function($string) { | |
| 279 | 279 | return mb_convert_case($string, MB_CASE_LOWER, "UTF-8"); | 
| 280 | 280 | }, | 
| 281 | -            'ucfirst' => function ($string) { | |
| 281 | +            'ucfirst' => function($string) { | |
| 282 | 282 | return mb_convert_case($string, MB_CASE_TITLE, "UTF-8"); | 
| 283 | 283 | }, | 
| 284 | -            'lcfirst' => function ($string) { | |
| 284 | +            'lcfirst' => function($string) { | |
| 285 | 285 | return lcfirst($string); | 
| 286 | 286 | }, | 
| 287 | -            'ltrim' => function ($string, $charlist = " \t\n\r\0\x0B") { | |
| 287 | +            'ltrim' => function($string, $charlist = " \t\n\r\0\x0B") { | |
| 288 | 288 | return ltrim($string, $charlist); | 
| 289 | 289 | }, | 
| 290 | -            'rtrim' => function ($string, $charlist = " \t\n\r\0\x0B") { | |
| 290 | +            'rtrim' => function($string, $charlist = " \t\n\r\0\x0B") { | |
| 291 | 291 | return rtrim($string, $charlist); | 
| 292 | 292 | }, | 
| 293 | -            'str_repeat' => function ($string, $multiplier = 1) { | |
| 293 | +            'str_repeat' => function($string, $multiplier = 1) { | |
| 294 | 294 | return str_repeat($string, $multiplier); | 
| 295 | 295 | }, | 
| 296 | -            'plural' => function ($string, $count = 2) { | |
| 296 | +            'plural' => function($string, $count = 2) { | |
| 297 | 297 | return str_plural($string, $count); | 
| 298 | 298 | }, | 
| 299 | -            'strpad' => function ($string, $pad_length, $pad_string = ' ') { | |
| 299 | +            'strpad' => function($string, $pad_length, $pad_string = ' ') { | |
| 300 | 300 | return str_pad($string, $pad_length, $pad_string, $pad_type = STR_PAD_BOTH); | 
| 301 | 301 | }, | 
| 302 | -            'leftpad' => function ($string, $pad_length, $pad_string = ' ') { | |
| 302 | +            'leftpad' => function($string, $pad_length, $pad_string = ' ') { | |
| 303 | 303 | return str_pad($string, $pad_length, $pad_string, $pad_type = STR_PAD_LEFT); | 
| 304 | 304 | }, | 
| 305 | -            'rightpad' => function ($string, $pad_length, $pad_string = ' ') { | |
| 305 | +            'rightpad' => function($string, $pad_length, $pad_string = ' ') { | |
| 306 | 306 | return str_pad($string, $pad_length, $pad_string, $pad_type = STR_PAD_RIGHT); | 
| 307 | 307 | }, | 
| 308 | -            'rtl' => function ($string) { | |
| 308 | +            'rtl' => function($string) { | |
| 309 | 309 | return strrev($string); | 
| 310 | 310 | }, | 
| 311 | -            'strip_tags' => function ($string, $allow = '') { | |
| 311 | +            'strip_tags' => function($string, $allow = '') { | |
| 312 | 312 | return strip_tags($string, $allow); | 
| 313 | 313 | }, | 
| 314 | -            'var_dump' => function ($expression) { | |
| 314 | +            'var_dump' => function($expression) { | |
| 315 | 315 | ob_start(); | 
| 316 | 316 | var_dump($expression); | 
| 317 | 317 | $result = ob_get_clean(); | 
| @@ -329,7 +329,7 @@ discard block | ||
| 329 | 329 | private function getConfigFunction() | 
| 330 | 330 |      { | 
| 331 | 331 | return [ | 
| 332 | -            'config' => function ($key = null, $default = null) { | |
| 332 | +            'config' => function($key = null, $default = null) { | |
| 333 | 333 | return config($key, $default); | 
| 334 | 334 | }, | 
| 335 | 335 | ]; | 
| @@ -343,7 +343,7 @@ discard block | ||
| 343 | 343 | private function getSessionFunction() | 
| 344 | 344 |      { | 
| 345 | 345 | return [ | 
| 346 | -            'session' => function ($key = null) { | |
| 346 | +            'session' => function($key = null) { | |
| 347 | 347 | return session($key); | 
| 348 | 348 | }, | 
| 349 | 349 | ]; | 
| @@ -357,7 +357,7 @@ discard block | ||
| 357 | 357 | private function getTransFunction() | 
| 358 | 358 |      { | 
| 359 | 359 | return [ | 
| 360 | -            'trans' => function ($key = null, $parameters = []) { | |
| 360 | +            'trans' => function($key = null, $parameters = []) { | |
| 361 | 361 | return trans($key, $parameters); | 
| 362 | 362 | }, | 
| 363 | 363 | ]; | 
| @@ -371,7 +371,7 @@ discard block | ||
| 371 | 371 | private function getVarDumpFunction() | 
| 372 | 372 |      { | 
| 373 | 373 | return [ | 
| 374 | -            'var_dump' => function ($expression) { | |
| 374 | +            'var_dump' => function($expression) { | |
| 375 | 375 | ob_start(); | 
| 376 | 376 | var_dump($expression); | 
| 377 | 377 | $result = ob_get_clean(); | 
| @@ -403,32 +403,32 @@ discard block | ||
| 403 | 403 | |
| 404 | 404 | // if we want just unprotected link | 
| 405 | 405 |          if (!$protected) { | 
| 406 | - return $link ? '<a href="mailto:' . $email . '">' . $linkText . '</a>' : $linkText; | |
| 406 | + return $link ? '<a href="mailto:'.$email.'">'.$linkText.'</a>' : $linkText; | |
| 407 | 407 | } | 
| 408 | 408 | |
| 409 | 409 | // turn on protection | 
| 410 | 410 | $character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'; | 
| 411 | 411 | $key = str_shuffle($character_set); | 
| 412 | 412 | $cipher_text = ''; | 
| 413 | - $id = 'e' . rand(1, 999999999); | |
| 413 | + $id = 'e'.rand(1, 999999999); | |
| 414 | 414 |          for ($i = 0; $i < strlen($email); $i += 1) { | 
| 415 | 415 | $cipher_text .= $key[strpos($character_set, $email[$i])]; | 
| 416 | 416 | } | 
| 417 | -        $script = 'var a="' . $key . '";var b=a.split("").sort().join("");var c="' . $cipher_text . '";var d="";'; | |
| 417 | +        $script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";'; | |
| 418 | 418 | $script .= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));'; | 
| 419 | 419 | $script .= 'var y = d;'; | 
| 420 | 420 |          if ($text !== null) { | 
| 421 | 421 | $script .= 'var y = "'.$text.'";'; | 
| 422 | 422 | } | 
| 423 | 423 |          if ($link) { | 
| 424 | -            $script .= 'document.getElementById("' . $id . '").innerHTML="<a href=\\"mailto:"+d+"\\">"+y+"</a>"'; | |
| 424 | +            $script .= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">"+y+"</a>"'; | |
| 425 | 425 |          } else { | 
| 426 | -            $script .= 'document.getElementById("' . $id . '").innerHTML=y'; | |
| 426 | +            $script .= 'document.getElementById("'.$id.'").innerHTML=y'; | |
| 427 | 427 | } | 
| 428 | -        $script = "eval(\"" . str_replace(array("\\", '"'), array("\\\\", '\"'), $script) . "\")"; | |
| 429 | - $script = '<script type="text/javascript">/*<![CDATA[*/' . $script . '/*]]>*/</script>'; | |
| 428 | +        $script = "eval(\"".str_replace(array("\\", '"'), array("\\\\", '\"'), $script)."\")"; | |
| 429 | + $script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>'; | |
| 430 | 430 | |
| 431 | - return '<span id="' . $id . '">[javascript protected email address]</span>' . $script; | |
| 431 | + return '<span id="'.$id.'">[javascript protected email address]</span>'.$script; | |
| 432 | 432 | } | 
| 433 | 433 | |
| 434 | 434 | /** | 
| @@ -443,15 +443,15 @@ discard block | ||
| 443 | 443 | private function getFileRevision() | 
| 444 | 444 |      { | 
| 445 | 445 | return [ | 
| 446 | -            'revision' => function ($filename, $format = null) { | |
| 446 | +            'revision' => function($filename, $format = null) { | |
| 447 | 447 | // Remove http/web address from the file name if there is one to load it locally | 
| 448 | 448 |                  $prefix = url('/'); | 
| 449 | -                $filename_ = trim(preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $filename), '/'); | |
| 449 | +                $filename_ = trim(preg_replace('/^'.preg_quote($prefix, '/').'/', '', $filename), '/'); | |
| 450 | 450 |                  if (file_exists($filename_)) { | 
| 451 | 451 | $timestamp = filemtime($filename_); | 
| 452 | 452 | $prepend = ($format) ? date($format, $timestamp) : $timestamp; | 
| 453 | 453 | |
| 454 | - return $filename . "?" . $prepend; | |
| 454 | + return $filename."?".$prepend; | |
| 455 | 455 | } | 
| 456 | 456 | |
| 457 | 457 | return $filename; | 
| @@ -7,7 +7,7 @@ discard block | ||
| 7 | 7 | use Twig_Environment; | 
| 8 | 8 | use VojtaSvoboda\TwigExtensions\Classes\TimeDiffTranslator; | 
| 9 | 9 | |
| 10 | -require_once __DIR__ . '/../vendor/autoload.php'; | |
| 10 | +require_once __DIR__.'/../vendor/autoload.php'; | |
| 11 | 11 | |
| 12 | 12 | class PluginTest extends PluginTestCase | 
| 13 | 13 |  { | 
| @@ -17,7 +17,7 @@ discard block | ||
| 17 | 17 | |
| 18 | 18 |          $this->app->setLocale('en'); | 
| 19 | 19 | |
| 20 | -        $this->app->singleton('time_diff_translator', function ($app) { | |
| 20 | +        $this->app->singleton('time_diff_translator', function($app) { | |
| 21 | 21 |              $loader = $app->make('translation.loader'); | 
| 22 | 22 |              $locale = $app->config->get('app.locale'); | 
| 23 | 23 | $translator = $app->make(TimeDiffTranslator::class, [$loader, $locale]); | 
| @@ -114,7 +114,7 @@ discard block | ||
| 114 | 114 | $twig = $this->getTwig(); | 
| 115 | 115 | |
| 116 | 116 | $now = Carbon::now()->subMinute(); | 
| 117 | -        $template = "{{ '" . $now->format('Y-m-d H:i:s') . "' | time_diff }}"; | |
| 117 | +        $template = "{{ '".$now->format('Y-m-d H:i:s')."' | time_diff }}"; | |
| 118 | 118 | |
| 119 | 119 | // this test fails at TravisCI and I don't know why | 
| 120 | 120 | $twigTemplate = $twig->createTemplate($template); | 
| @@ -341,7 +341,7 @@ discard block | ||
| 341 | 341 | $key = 'app.custom.key'; | 
| 342 | 342 | $value = 'test value'; | 
| 343 | 343 | Config::set($key, $value); | 
| 344 | -        $template = "{{ config('" . $key . "') }}"; | |
| 344 | +        $template = "{{ config('".$key."') }}"; | |
| 345 | 345 | |
| 346 | 346 | $twigTemplate = $twig->createTemplate($template); | 
| 347 | 347 | $this->assertEquals($twigTemplate->render([]), $value); |