@@ -4,36 +4,36 @@ |
||
4 | 4 | |
5 | 5 | abstract class BaseTranslator implements TranslatorInterface |
6 | 6 | { |
7 | - /** @var TranslatorInterface */ |
|
8 | - public static $current; |
|
9 | - |
|
10 | - /** |
|
11 | - * @see TranslatorInterface |
|
12 | - */ |
|
13 | - public function noop($original) |
|
14 | - { |
|
15 | - return $original; |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @see TranslatorInterface |
|
20 | - */ |
|
21 | - public function register() |
|
22 | - { |
|
23 | - $previous = static::$current; |
|
24 | - |
|
25 | - static::$current = $this; |
|
26 | - |
|
27 | - static::includeFunctions(); |
|
28 | - |
|
29 | - return $previous; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Include the gettext functions |
|
34 | - */ |
|
35 | - public static function includeFunctions() |
|
36 | - { |
|
37 | - include_once __DIR__.'/translator_functions.php'; |
|
38 | - } |
|
7 | + /** @var TranslatorInterface */ |
|
8 | + public static $current; |
|
9 | + |
|
10 | + /** |
|
11 | + * @see TranslatorInterface |
|
12 | + */ |
|
13 | + public function noop($original) |
|
14 | + { |
|
15 | + return $original; |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @see TranslatorInterface |
|
20 | + */ |
|
21 | + public function register() |
|
22 | + { |
|
23 | + $previous = static::$current; |
|
24 | + |
|
25 | + static::$current = $this; |
|
26 | + |
|
27 | + static::includeFunctions(); |
|
28 | + |
|
29 | + return $previous; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Include the gettext functions |
|
34 | + */ |
|
35 | + public static function includeFunctions() |
|
36 | + { |
|
37 | + include_once __DIR__.'/translator_functions.php'; |
|
38 | + } |
|
39 | 39 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * @see TranslatorInterface |
12 | 12 | */ |
13 | - public function noop($original) |
|
13 | + public function noop( $original ) |
|
14 | 14 | { |
15 | 15 | return $original; |
16 | 16 | } |
@@ -34,6 +34,6 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public static function includeFunctions() |
36 | 36 | { |
37 | - include_once __DIR__.'/translator_functions.php'; |
|
37 | + include_once __DIR__ . '/translator_functions.php'; |
|
38 | 38 | } |
39 | 39 | } |
@@ -2,24 +2,21 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext; |
4 | 4 | |
5 | -abstract class BaseTranslator implements TranslatorInterface |
|
6 | -{ |
|
5 | +abstract class BaseTranslator implements TranslatorInterface { |
|
7 | 6 | /** @var TranslatorInterface */ |
8 | 7 | public static $current; |
9 | 8 | |
10 | 9 | /** |
11 | 10 | * @see TranslatorInterface |
12 | 11 | */ |
13 | - public function noop($original) |
|
14 | - { |
|
12 | + public function noop($original) { |
|
15 | 13 | return $original; |
16 | 14 | } |
17 | 15 | |
18 | 16 | /** |
19 | 17 | * @see TranslatorInterface |
20 | 18 | */ |
21 | - public function register() |
|
22 | - { |
|
19 | + public function register() { |
|
23 | 20 | $previous = static::$current; |
24 | 21 | |
25 | 22 | static::$current = $this; |
@@ -32,8 +29,7 @@ discard block |
||
32 | 29 | /** |
33 | 30 | * Include the gettext functions |
34 | 31 | */ |
35 | - public static function includeFunctions() |
|
36 | - { |
|
32 | + public static function includeFunctions() { |
|
37 | 33 | include_once __DIR__.'/translator_functions.php'; |
38 | 34 | } |
39 | 35 | } |
@@ -4,158 +4,158 @@ |
||
4 | 4 | |
5 | 5 | class GettextTranslator extends BaseTranslator implements TranslatorInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * Constructor. Detects the current language using the environment variables. |
|
9 | - * |
|
10 | - * @param string $language |
|
11 | - */ |
|
12 | - public function __construct($language = null) |
|
13 | - { |
|
14 | - if (!function_exists('gettext')) { |
|
15 | - throw new \RuntimeException('This class require the gettext extension for PHP'); |
|
16 | - } |
|
17 | - |
|
18 | - //detects the language environment respecting the priority order |
|
19 | - //http://php.net/manual/en/function.gettext.php#114062 |
|
20 | - if (empty($language)) { |
|
21 | - $language = getenv('LANGUAGE') ?: getenv('LC_ALL') ?: getenv('LC_MESSAGES') ?: getenv('LANG'); |
|
22 | - } |
|
23 | - |
|
24 | - if (!empty($language)) { |
|
25 | - $this->setLanguage($language); |
|
26 | - } |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Define the current locale. |
|
31 | - * |
|
32 | - * @param string $language |
|
33 | - * @param int|null $category |
|
34 | - * |
|
35 | - * @return self |
|
36 | - */ |
|
37 | - public function setLanguage($language, $category = null) |
|
38 | - { |
|
39 | - if ($category === null) { |
|
40 | - $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; |
|
41 | - } |
|
42 | - |
|
43 | - setlocale($category, $language); |
|
44 | - putenv('LANGUAGE='.$language); |
|
45 | - |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Loads a gettext domain. |
|
51 | - * |
|
52 | - * @param string $domain |
|
53 | - * @param string $path |
|
54 | - * @param bool $default |
|
55 | - * |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public function loadDomain($domain, $path = null, $default = true) |
|
59 | - { |
|
60 | - bindtextdomain($domain, $path); |
|
61 | - bind_textdomain_codeset($domain, 'UTF-8'); |
|
62 | - |
|
63 | - if ($default) { |
|
64 | - textdomain($domain); |
|
65 | - } |
|
66 | - |
|
67 | - return $this; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @see TranslatorInterface |
|
72 | - * |
|
73 | - * {@inheritdoc} |
|
74 | - */ |
|
75 | - public function gettext($original) |
|
76 | - { |
|
77 | - return gettext($original); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @see TranslatorInterface |
|
82 | - * |
|
83 | - * {@inheritdoc} |
|
84 | - */ |
|
85 | - public function ngettext($original, $plural, $value) |
|
86 | - { |
|
87 | - return ngettext($original, $plural, $value); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @see TranslatorInterface |
|
92 | - * |
|
93 | - * {@inheritdoc} |
|
94 | - */ |
|
95 | - public function dngettext($domain, $original, $plural, $value) |
|
96 | - { |
|
97 | - return dngettext($domain, $original, $plural, $value); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @see TranslatorInterface |
|
102 | - * |
|
103 | - * {@inheritdoc} |
|
104 | - */ |
|
105 | - public function npgettext($context, $original, $plural, $value) |
|
106 | - { |
|
107 | - $message = $context."\x04".$original; |
|
108 | - $translation = ngettext($message, $plural, $value); |
|
109 | - |
|
110 | - return ($translation === $message) ? $original : $translation; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @see TranslatorInterface |
|
115 | - * |
|
116 | - * {@inheritdoc} |
|
117 | - */ |
|
118 | - public function pgettext($context, $original) |
|
119 | - { |
|
120 | - $message = $context."\x04".$original; |
|
121 | - $translation = gettext($message); |
|
122 | - |
|
123 | - return ($translation === $message) ? $original : $translation; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @see TranslatorInterface |
|
128 | - * |
|
129 | - * {@inheritdoc} |
|
130 | - */ |
|
131 | - public function dgettext($domain, $original) |
|
132 | - { |
|
133 | - return dgettext($domain, $original); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @see TranslatorInterface |
|
138 | - * |
|
139 | - * {@inheritdoc} |
|
140 | - */ |
|
141 | - public function dpgettext($domain, $context, $original) |
|
142 | - { |
|
143 | - $message = $context."\x04".$original; |
|
144 | - $translation = dgettext($domain, $message); |
|
145 | - |
|
146 | - return ($translation === $message) ? $original : $translation; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @see TranslatorInterface |
|
151 | - * |
|
152 | - * {@inheritdoc} |
|
153 | - */ |
|
154 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
155 | - { |
|
156 | - $message = $context."\x04".$original; |
|
157 | - $translation = dngettext($domain, $message, $plural, $value); |
|
158 | - |
|
159 | - return ($translation === $message) ? $original : $translation; |
|
160 | - } |
|
7 | + /** |
|
8 | + * Constructor. Detects the current language using the environment variables. |
|
9 | + * |
|
10 | + * @param string $language |
|
11 | + */ |
|
12 | + public function __construct($language = null) |
|
13 | + { |
|
14 | + if (!function_exists('gettext')) { |
|
15 | + throw new \RuntimeException('This class require the gettext extension for PHP'); |
|
16 | + } |
|
17 | + |
|
18 | + //detects the language environment respecting the priority order |
|
19 | + //http://php.net/manual/en/function.gettext.php#114062 |
|
20 | + if (empty($language)) { |
|
21 | + $language = getenv('LANGUAGE') ?: getenv('LC_ALL') ?: getenv('LC_MESSAGES') ?: getenv('LANG'); |
|
22 | + } |
|
23 | + |
|
24 | + if (!empty($language)) { |
|
25 | + $this->setLanguage($language); |
|
26 | + } |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Define the current locale. |
|
31 | + * |
|
32 | + * @param string $language |
|
33 | + * @param int|null $category |
|
34 | + * |
|
35 | + * @return self |
|
36 | + */ |
|
37 | + public function setLanguage($language, $category = null) |
|
38 | + { |
|
39 | + if ($category === null) { |
|
40 | + $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; |
|
41 | + } |
|
42 | + |
|
43 | + setlocale($category, $language); |
|
44 | + putenv('LANGUAGE='.$language); |
|
45 | + |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Loads a gettext domain. |
|
51 | + * |
|
52 | + * @param string $domain |
|
53 | + * @param string $path |
|
54 | + * @param bool $default |
|
55 | + * |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public function loadDomain($domain, $path = null, $default = true) |
|
59 | + { |
|
60 | + bindtextdomain($domain, $path); |
|
61 | + bind_textdomain_codeset($domain, 'UTF-8'); |
|
62 | + |
|
63 | + if ($default) { |
|
64 | + textdomain($domain); |
|
65 | + } |
|
66 | + |
|
67 | + return $this; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @see TranslatorInterface |
|
72 | + * |
|
73 | + * {@inheritdoc} |
|
74 | + */ |
|
75 | + public function gettext($original) |
|
76 | + { |
|
77 | + return gettext($original); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @see TranslatorInterface |
|
82 | + * |
|
83 | + * {@inheritdoc} |
|
84 | + */ |
|
85 | + public function ngettext($original, $plural, $value) |
|
86 | + { |
|
87 | + return ngettext($original, $plural, $value); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @see TranslatorInterface |
|
92 | + * |
|
93 | + * {@inheritdoc} |
|
94 | + */ |
|
95 | + public function dngettext($domain, $original, $plural, $value) |
|
96 | + { |
|
97 | + return dngettext($domain, $original, $plural, $value); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @see TranslatorInterface |
|
102 | + * |
|
103 | + * {@inheritdoc} |
|
104 | + */ |
|
105 | + public function npgettext($context, $original, $plural, $value) |
|
106 | + { |
|
107 | + $message = $context."\x04".$original; |
|
108 | + $translation = ngettext($message, $plural, $value); |
|
109 | + |
|
110 | + return ($translation === $message) ? $original : $translation; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @see TranslatorInterface |
|
115 | + * |
|
116 | + * {@inheritdoc} |
|
117 | + */ |
|
118 | + public function pgettext($context, $original) |
|
119 | + { |
|
120 | + $message = $context."\x04".$original; |
|
121 | + $translation = gettext($message); |
|
122 | + |
|
123 | + return ($translation === $message) ? $original : $translation; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @see TranslatorInterface |
|
128 | + * |
|
129 | + * {@inheritdoc} |
|
130 | + */ |
|
131 | + public function dgettext($domain, $original) |
|
132 | + { |
|
133 | + return dgettext($domain, $original); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @see TranslatorInterface |
|
138 | + * |
|
139 | + * {@inheritdoc} |
|
140 | + */ |
|
141 | + public function dpgettext($domain, $context, $original) |
|
142 | + { |
|
143 | + $message = $context."\x04".$original; |
|
144 | + $translation = dgettext($domain, $message); |
|
145 | + |
|
146 | + return ($translation === $message) ? $original : $translation; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @see TranslatorInterface |
|
151 | + * |
|
152 | + * {@inheritdoc} |
|
153 | + */ |
|
154 | + public function dnpgettext($domain, $context, $original, $plural, $value) |
|
155 | + { |
|
156 | + $message = $context."\x04".$original; |
|
157 | + $translation = dngettext($domain, $message, $plural, $value); |
|
158 | + |
|
159 | + return ($translation === $message) ? $original : $translation; |
|
160 | + } |
|
161 | 161 | } |
@@ -9,20 +9,20 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @param string $language |
11 | 11 | */ |
12 | - public function __construct($language = null) |
|
12 | + public function __construct( $language = null ) |
|
13 | 13 | { |
14 | - if (!function_exists('gettext')) { |
|
15 | - throw new \RuntimeException('This class require the gettext extension for PHP'); |
|
14 | + if ( ! function_exists( 'gettext' ) ) { |
|
15 | + throw new \RuntimeException( 'This class require the gettext extension for PHP' ); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | //detects the language environment respecting the priority order |
19 | 19 | //http://php.net/manual/en/function.gettext.php#114062 |
20 | - if (empty($language)) { |
|
21 | - $language = getenv('LANGUAGE') ?: getenv('LC_ALL') ?: getenv('LC_MESSAGES') ?: getenv('LANG'); |
|
20 | + if ( empty( $language ) ) { |
|
21 | + $language = getenv( 'LANGUAGE' ) ?: getenv( 'LC_ALL' ) ?: getenv( 'LC_MESSAGES' ) ?: getenv( 'LANG' ); |
|
22 | 22 | } |
23 | 23 | |
24 | - if (!empty($language)) { |
|
25 | - $this->setLanguage($language); |
|
24 | + if ( ! empty( $language ) ) { |
|
25 | + $this->setLanguage( $language ); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return self |
36 | 36 | */ |
37 | - public function setLanguage($language, $category = null) |
|
37 | + public function setLanguage( $language, $category = null ) |
|
38 | 38 | { |
39 | - if ($category === null) { |
|
40 | - $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; |
|
39 | + if ( $category === null ) { |
|
40 | + $category = defined( 'LC_MESSAGES' ) ? LC_MESSAGES : LC_ALL; |
|
41 | 41 | } |
42 | 42 | |
43 | - setlocale($category, $language); |
|
44 | - putenv('LANGUAGE='.$language); |
|
43 | + setlocale( $category, $language ); |
|
44 | + putenv( 'LANGUAGE=' . $language ); |
|
45 | 45 | |
46 | 46 | return $this; |
47 | 47 | } |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return self |
57 | 57 | */ |
58 | - public function loadDomain($domain, $path = null, $default = true) |
|
58 | + public function loadDomain( $domain, $path = null, $default = true ) |
|
59 | 59 | { |
60 | - bindtextdomain($domain, $path); |
|
61 | - bind_textdomain_codeset($domain, 'UTF-8'); |
|
60 | + bindtextdomain( $domain, $path ); |
|
61 | + bind_textdomain_codeset( $domain, 'UTF-8' ); |
|
62 | 62 | |
63 | - if ($default) { |
|
64 | - textdomain($domain); |
|
63 | + if ( $default ) { |
|
64 | + textdomain( $domain ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | return $this; |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | * |
73 | 73 | * {@inheritdoc} |
74 | 74 | */ |
75 | - public function gettext($original) |
|
75 | + public function gettext( $original ) |
|
76 | 76 | { |
77 | - return gettext($original); |
|
77 | + return gettext( $original ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * |
83 | 83 | * {@inheritdoc} |
84 | 84 | */ |
85 | - public function ngettext($original, $plural, $value) |
|
85 | + public function ngettext( $original, $plural, $value ) |
|
86 | 86 | { |
87 | - return ngettext($original, $plural, $value); |
|
87 | + return ngettext( $original, $plural, $value ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * |
93 | 93 | * {@inheritdoc} |
94 | 94 | */ |
95 | - public function dngettext($domain, $original, $plural, $value) |
|
95 | + public function dngettext( $domain, $original, $plural, $value ) |
|
96 | 96 | { |
97 | - return dngettext($domain, $original, $plural, $value); |
|
97 | + return dngettext( $domain, $original, $plural, $value ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | * |
103 | 103 | * {@inheritdoc} |
104 | 104 | */ |
105 | - public function npgettext($context, $original, $plural, $value) |
|
105 | + public function npgettext( $context, $original, $plural, $value ) |
|
106 | 106 | { |
107 | - $message = $context."\x04".$original; |
|
108 | - $translation = ngettext($message, $plural, $value); |
|
107 | + $message = $context . "\x04" . $original; |
|
108 | + $translation = ngettext( $message, $plural, $value ); |
|
109 | 109 | |
110 | - return ($translation === $message) ? $original : $translation; |
|
110 | + return ( $translation === $message ) ? $original : $translation; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * |
116 | 116 | * {@inheritdoc} |
117 | 117 | */ |
118 | - public function pgettext($context, $original) |
|
118 | + public function pgettext( $context, $original ) |
|
119 | 119 | { |
120 | - $message = $context."\x04".$original; |
|
121 | - $translation = gettext($message); |
|
120 | + $message = $context . "\x04" . $original; |
|
121 | + $translation = gettext( $message ); |
|
122 | 122 | |
123 | - return ($translation === $message) ? $original : $translation; |
|
123 | + return ( $translation === $message ) ? $original : $translation; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * {@inheritdoc} |
130 | 130 | */ |
131 | - public function dgettext($domain, $original) |
|
131 | + public function dgettext( $domain, $original ) |
|
132 | 132 | { |
133 | - return dgettext($domain, $original); |
|
133 | + return dgettext( $domain, $original ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * |
139 | 139 | * {@inheritdoc} |
140 | 140 | */ |
141 | - public function dpgettext($domain, $context, $original) |
|
141 | + public function dpgettext( $domain, $context, $original ) |
|
142 | 142 | { |
143 | - $message = $context."\x04".$original; |
|
144 | - $translation = dgettext($domain, $message); |
|
143 | + $message = $context . "\x04" . $original; |
|
144 | + $translation = dgettext( $domain, $message ); |
|
145 | 145 | |
146 | - return ($translation === $message) ? $original : $translation; |
|
146 | + return ( $translation === $message ) ? $original : $translation; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * |
152 | 152 | * {@inheritdoc} |
153 | 153 | */ |
154 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
154 | + public function dnpgettext( $domain, $context, $original, $plural, $value ) |
|
155 | 155 | { |
156 | - $message = $context."\x04".$original; |
|
157 | - $translation = dngettext($domain, $message, $plural, $value); |
|
156 | + $message = $context . "\x04" . $original; |
|
157 | + $translation = dngettext( $domain, $message, $plural, $value ); |
|
158 | 158 | |
159 | - return ($translation === $message) ? $original : $translation; |
|
159 | + return ( $translation === $message ) ? $original : $translation; |
|
160 | 160 | } |
161 | 161 | } |
@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext; |
4 | 4 | |
5 | -class GettextTranslator extends BaseTranslator implements TranslatorInterface |
|
6 | -{ |
|
5 | +class GettextTranslator extends BaseTranslator implements TranslatorInterface { |
|
7 | 6 | /** |
8 | 7 | * Constructor. Detects the current language using the environment variables. |
9 | 8 | * |
10 | 9 | * @param string $language |
11 | 10 | */ |
12 | - public function __construct($language = null) |
|
13 | - { |
|
11 | + public function __construct($language = null) { |
|
14 | 12 | if (!function_exists('gettext')) { |
15 | 13 | throw new \RuntimeException('This class require the gettext extension for PHP'); |
16 | 14 | } |
@@ -34,8 +32,7 @@ discard block |
||
34 | 32 | * |
35 | 33 | * @return self |
36 | 34 | */ |
37 | - public function setLanguage($language, $category = null) |
|
38 | - { |
|
35 | + public function setLanguage($language, $category = null) { |
|
39 | 36 | if ($category === null) { |
40 | 37 | $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; |
41 | 38 | } |
@@ -55,8 +52,7 @@ discard block |
||
55 | 52 | * |
56 | 53 | * @return self |
57 | 54 | */ |
58 | - public function loadDomain($domain, $path = null, $default = true) |
|
59 | - { |
|
55 | + public function loadDomain($domain, $path = null, $default = true) { |
|
60 | 56 | bindtextdomain($domain, $path); |
61 | 57 | bind_textdomain_codeset($domain, 'UTF-8'); |
62 | 58 | |
@@ -72,8 +68,7 @@ discard block |
||
72 | 68 | * |
73 | 69 | * {@inheritdoc} |
74 | 70 | */ |
75 | - public function gettext($original) |
|
76 | - { |
|
71 | + public function gettext($original) { |
|
77 | 72 | return gettext($original); |
78 | 73 | } |
79 | 74 | |
@@ -82,8 +77,7 @@ discard block |
||
82 | 77 | * |
83 | 78 | * {@inheritdoc} |
84 | 79 | */ |
85 | - public function ngettext($original, $plural, $value) |
|
86 | - { |
|
80 | + public function ngettext($original, $plural, $value) { |
|
87 | 81 | return ngettext($original, $plural, $value); |
88 | 82 | } |
89 | 83 | |
@@ -92,8 +86,7 @@ discard block |
||
92 | 86 | * |
93 | 87 | * {@inheritdoc} |
94 | 88 | */ |
95 | - public function dngettext($domain, $original, $plural, $value) |
|
96 | - { |
|
89 | + public function dngettext($domain, $original, $plural, $value) { |
|
97 | 90 | return dngettext($domain, $original, $plural, $value); |
98 | 91 | } |
99 | 92 | |
@@ -102,8 +95,7 @@ discard block |
||
102 | 95 | * |
103 | 96 | * {@inheritdoc} |
104 | 97 | */ |
105 | - public function npgettext($context, $original, $plural, $value) |
|
106 | - { |
|
98 | + public function npgettext($context, $original, $plural, $value) { |
|
107 | 99 | $message = $context."\x04".$original; |
108 | 100 | $translation = ngettext($message, $plural, $value); |
109 | 101 | |
@@ -115,8 +107,7 @@ discard block |
||
115 | 107 | * |
116 | 108 | * {@inheritdoc} |
117 | 109 | */ |
118 | - public function pgettext($context, $original) |
|
119 | - { |
|
110 | + public function pgettext($context, $original) { |
|
120 | 111 | $message = $context."\x04".$original; |
121 | 112 | $translation = gettext($message); |
122 | 113 | |
@@ -128,8 +119,7 @@ discard block |
||
128 | 119 | * |
129 | 120 | * {@inheritdoc} |
130 | 121 | */ |
131 | - public function dgettext($domain, $original) |
|
132 | - { |
|
122 | + public function dgettext($domain, $original) { |
|
133 | 123 | return dgettext($domain, $original); |
134 | 124 | } |
135 | 125 | |
@@ -138,8 +128,7 @@ discard block |
||
138 | 128 | * |
139 | 129 | * {@inheritdoc} |
140 | 130 | */ |
141 | - public function dpgettext($domain, $context, $original) |
|
142 | - { |
|
131 | + public function dpgettext($domain, $context, $original) { |
|
143 | 132 | $message = $context."\x04".$original; |
144 | 133 | $translation = dgettext($domain, $message); |
145 | 134 | |
@@ -151,8 +140,7 @@ discard block |
||
151 | 140 | * |
152 | 141 | * {@inheritdoc} |
153 | 142 | */ |
154 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
155 | - { |
|
143 | + public function dnpgettext($domain, $context, $original, $plural, $value) { |
|
156 | 144 | $message = $context."\x04".$original; |
157 | 145 | $translation = dngettext($domain, $message, $plural, $value); |
158 | 146 |
@@ -9,21 +9,21 @@ |
||
9 | 9 | */ |
10 | 10 | trait HeadersGeneratorTrait |
11 | 11 | { |
12 | - /** |
|
13 | - * Returns the headers as a string. |
|
14 | - * |
|
15 | - * @param Translations $translations |
|
16 | - * |
|
17 | - * @return string |
|
18 | - */ |
|
19 | - protected static function generateHeaders(Translations $translations) |
|
20 | - { |
|
21 | - $headers = ''; |
|
12 | + /** |
|
13 | + * Returns the headers as a string. |
|
14 | + * |
|
15 | + * @param Translations $translations |
|
16 | + * |
|
17 | + * @return string |
|
18 | + */ |
|
19 | + protected static function generateHeaders(Translations $translations) |
|
20 | + { |
|
21 | + $headers = ''; |
|
22 | 22 | |
23 | - foreach ($translations->getHeaders() as $name => $value) { |
|
24 | - $headers .= sprintf("%s: %s\n", $name, $value); |
|
25 | - } |
|
23 | + foreach ($translations->getHeaders() as $name => $value) { |
|
24 | + $headers .= sprintf("%s: %s\n", $name, $value); |
|
25 | + } |
|
26 | 26 | |
27 | - return $headers; |
|
28 | - } |
|
27 | + return $headers; |
|
28 | + } |
|
29 | 29 | } |
@@ -16,12 +16,12 @@ |
||
16 | 16 | * |
17 | 17 | * @return string |
18 | 18 | */ |
19 | - protected static function generateHeaders(Translations $translations) |
|
19 | + protected static function generateHeaders( Translations $translations ) |
|
20 | 20 | { |
21 | 21 | $headers = ''; |
22 | 22 | |
23 | - foreach ($translations->getHeaders() as $name => $value) { |
|
24 | - $headers .= sprintf("%s: %s\n", $name, $value); |
|
23 | + foreach ( $translations->getHeaders() as $name => $value ) { |
|
24 | + $headers .= sprintf( "%s: %s\n", $name, $value ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | return $headers; |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Trait to provide the functionality of extracting headers. |
9 | 9 | */ |
10 | -trait HeadersGeneratorTrait |
|
11 | -{ |
|
10 | +trait HeadersGeneratorTrait { |
|
12 | 11 | /** |
13 | 12 | * Returns the headers as a string. |
14 | 13 | * |
@@ -16,8 +15,7 @@ discard block |
||
16 | 15 | * |
17 | 16 | * @return string |
18 | 17 | */ |
19 | - protected static function generateHeaders(Translations $translations) |
|
20 | - { |
|
18 | + protected static function generateHeaders(Translations $translations) { |
|
21 | 19 | $headers = ''; |
22 | 20 | |
23 | 21 | foreach ($translations->getHeaders() as $name => $value) { |
@@ -9,51 +9,51 @@ |
||
9 | 9 | */ |
10 | 10 | trait DictionaryTrait |
11 | 11 | { |
12 | - use HeadersGeneratorTrait; |
|
13 | - use HeadersExtractorTrait; |
|
14 | - |
|
15 | - /** |
|
16 | - * Returns a plain dictionary with the format [original => translation]. |
|
17 | - * |
|
18 | - * @param Translations $translations |
|
19 | - * @param bool $includeHeaders |
|
20 | - * |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - protected static function toArray(Translations $translations, $includeHeaders) |
|
24 | - { |
|
25 | - $messages = []; |
|
26 | - |
|
27 | - if ($includeHeaders) { |
|
28 | - $messages[''] = static::generateHeaders($translations); |
|
29 | - } |
|
30 | - |
|
31 | - foreach ($translations as $translation) { |
|
32 | - if ($translation->isDisabled()) { |
|
33 | - continue; |
|
34 | - } |
|
35 | - |
|
36 | - $messages[$translation->getOriginal()] = $translation->getTranslation(); |
|
37 | - } |
|
38 | - |
|
39 | - return $messages; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Extract the entries from a dictionary. |
|
44 | - * |
|
45 | - * @param array $messages |
|
46 | - * @param Translations $translations |
|
47 | - */ |
|
48 | - protected static function fromArray(array $messages, Translations $translations) |
|
49 | - { |
|
50 | - foreach ($messages as $original => $translation) { |
|
51 | - if ($original === '') { |
|
52 | - static::extractHeaders($translation, $translations); |
|
53 | - continue; |
|
54 | - } |
|
55 | - |
|
56 | - $translations->insert(null, $original)->setTranslation($translation); |
|
57 | - } |
|
58 | - } |
|
12 | + use HeadersGeneratorTrait; |
|
13 | + use HeadersExtractorTrait; |
|
14 | + |
|
15 | + /** |
|
16 | + * Returns a plain dictionary with the format [original => translation]. |
|
17 | + * |
|
18 | + * @param Translations $translations |
|
19 | + * @param bool $includeHeaders |
|
20 | + * |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + protected static function toArray(Translations $translations, $includeHeaders) |
|
24 | + { |
|
25 | + $messages = []; |
|
26 | + |
|
27 | + if ($includeHeaders) { |
|
28 | + $messages[''] = static::generateHeaders($translations); |
|
29 | + } |
|
30 | + |
|
31 | + foreach ($translations as $translation) { |
|
32 | + if ($translation->isDisabled()) { |
|
33 | + continue; |
|
34 | + } |
|
35 | + |
|
36 | + $messages[$translation->getOriginal()] = $translation->getTranslation(); |
|
37 | + } |
|
38 | + |
|
39 | + return $messages; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Extract the entries from a dictionary. |
|
44 | + * |
|
45 | + * @param array $messages |
|
46 | + * @param Translations $translations |
|
47 | + */ |
|
48 | + protected static function fromArray(array $messages, Translations $translations) |
|
49 | + { |
|
50 | + foreach ($messages as $original => $translation) { |
|
51 | + if ($original === '') { |
|
52 | + static::extractHeaders($translation, $translations); |
|
53 | + continue; |
|
54 | + } |
|
55 | + |
|
56 | + $translations->insert(null, $original)->setTranslation($translation); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | } |
@@ -20,20 +20,20 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return array |
22 | 22 | */ |
23 | - protected static function toArray(Translations $translations, $includeHeaders) |
|
23 | + protected static function toArray( Translations $translations, $includeHeaders ) |
|
24 | 24 | { |
25 | - $messages = []; |
|
25 | + $messages = [ ]; |
|
26 | 26 | |
27 | - if ($includeHeaders) { |
|
28 | - $messages[''] = static::generateHeaders($translations); |
|
27 | + if ( $includeHeaders ) { |
|
28 | + $messages[ '' ] = static::generateHeaders( $translations ); |
|
29 | 29 | } |
30 | 30 | |
31 | - foreach ($translations as $translation) { |
|
32 | - if ($translation->isDisabled()) { |
|
31 | + foreach ( $translations as $translation ) { |
|
32 | + if ( $translation->isDisabled() ) { |
|
33 | 33 | continue; |
34 | 34 | } |
35 | 35 | |
36 | - $messages[$translation->getOriginal()] = $translation->getTranslation(); |
|
36 | + $messages[ $translation->getOriginal() ] = $translation->getTranslation(); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $messages; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | * @param array $messages |
46 | 46 | * @param Translations $translations |
47 | 47 | */ |
48 | - protected static function fromArray(array $messages, Translations $translations) |
|
48 | + protected static function fromArray( array $messages, Translations $translations ) |
|
49 | 49 | { |
50 | - foreach ($messages as $original => $translation) { |
|
51 | - if ($original === '') { |
|
52 | - static::extractHeaders($translation, $translations); |
|
50 | + foreach ( $messages as $original => $translation ) { |
|
51 | + if ( $original === '' ) { |
|
52 | + static::extractHeaders( $translation, $translations ); |
|
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | - $translations->insert(null, $original)->setTranslation($translation); |
|
56 | + $translations->insert( null, $original )->setTranslation( $translation ); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Trait used by all generators that exports the translations to plain dictionary (original => singular-translation). |
9 | 9 | */ |
10 | -trait DictionaryTrait |
|
11 | -{ |
|
10 | +trait DictionaryTrait { |
|
12 | 11 | use HeadersGeneratorTrait; |
13 | 12 | use HeadersExtractorTrait; |
14 | 13 | |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * |
21 | 20 | * @return array |
22 | 21 | */ |
23 | - protected static function toArray(Translations $translations, $includeHeaders) |
|
24 | - { |
|
22 | + protected static function toArray(Translations $translations, $includeHeaders) { |
|
25 | 23 | $messages = []; |
26 | 24 | |
27 | 25 | if ($includeHeaders) { |
@@ -45,8 +43,7 @@ discard block |
||
45 | 43 | * @param array $messages |
46 | 44 | * @param Translations $translations |
47 | 45 | */ |
48 | - protected static function fromArray(array $messages, Translations $translations) |
|
49 | - { |
|
46 | + protected static function fromArray(array $messages, Translations $translations) { |
|
50 | 47 | foreach ($messages as $original => $translation) { |
51 | 48 | if ($original === '') { |
52 | 49 | static::extractHeaders($translation, $translations); |
@@ -4,317 +4,317 @@ |
||
4 | 4 | |
5 | 5 | class JsFunctionsScanner extends FunctionsScanner |
6 | 6 | { |
7 | - protected $code; |
|
8 | - protected $status = []; |
|
9 | - |
|
10 | - /** |
|
11 | - * Constructor. |
|
12 | - * |
|
13 | - * @param string $code The php code to scan |
|
14 | - */ |
|
15 | - public function __construct($code) |
|
16 | - { |
|
17 | - // Normalize newline characters |
|
18 | - $this->code = str_replace(["\r\n", "\n\r", "\r"], "\n", $code); |
|
19 | - } |
|
20 | - |
|
21 | - /** |
|
22 | - * {@inheritdoc} |
|
23 | - */ |
|
24 | - public function getFunctions(array $constants = []) |
|
25 | - { |
|
26 | - $length = strlen($this->code); |
|
27 | - $line = 1; |
|
28 | - $buffer = ''; |
|
29 | - $functions = []; |
|
30 | - $bufferFunctions = []; |
|
31 | - $char = null; |
|
32 | - |
|
33 | - for ($pos = 0; $pos < $length; ++$pos) { |
|
34 | - $prev = $char; |
|
35 | - $char = $this->code[$pos]; |
|
36 | - $next = isset($this->code[$pos + 1]) ? $this->code[$pos + 1] : null; |
|
37 | - |
|
38 | - switch ($char) { |
|
39 | - case '\\': |
|
40 | - switch ($this->status()) { |
|
41 | - case 'simple-quote': |
|
42 | - if ($next !== "'") { |
|
43 | - break 2; |
|
44 | - } |
|
45 | - break; |
|
46 | - |
|
47 | - case 'double-quote': |
|
48 | - if ($next !== '"') { |
|
49 | - break 2; |
|
50 | - } |
|
51 | - break; |
|
52 | - |
|
53 | - case 'back-tick': |
|
54 | - if ($next !== '`') { |
|
55 | - break 2; |
|
56 | - } |
|
57 | - break; |
|
58 | - } |
|
59 | - |
|
60 | - $prev = $char; |
|
61 | - $char = $next; |
|
62 | - $pos++; |
|
63 | - $next = isset($this->code[$pos]) ? $this->code[$pos] : null; |
|
64 | - break; |
|
65 | - |
|
66 | - case "\n": |
|
67 | - ++$line; |
|
68 | - |
|
69 | - if ($this->status('line-comment')) { |
|
70 | - $this->upStatus(); |
|
71 | - } |
|
72 | - break; |
|
73 | - |
|
74 | - case '/': |
|
75 | - switch ($this->status()) { |
|
76 | - case 'simple-quote': |
|
77 | - case 'double-quote': |
|
78 | - case 'back-tick': |
|
79 | - case 'line-comment': |
|
80 | - break; |
|
81 | - |
|
82 | - case 'block-comment': |
|
83 | - if ($prev === '*') { |
|
84 | - $this->upStatus(); |
|
85 | - } |
|
86 | - break; |
|
87 | - |
|
88 | - default: |
|
89 | - if ($next === '/') { |
|
90 | - $this->downStatus('line-comment'); |
|
91 | - } elseif ($next === '*') { |
|
92 | - $this->downStatus('block-comment'); |
|
93 | - } |
|
94 | - break; |
|
95 | - } |
|
96 | - break; |
|
97 | - |
|
98 | - case "'": |
|
99 | - switch ($this->status()) { |
|
100 | - case 'simple-quote': |
|
101 | - $this->upStatus(); |
|
102 | - break; |
|
103 | - |
|
104 | - case 'line-comment': |
|
105 | - case 'block-comment': |
|
106 | - case 'double-quote': |
|
107 | - case 'back-tick': |
|
108 | - break; |
|
109 | - |
|
110 | - default: |
|
111 | - $this->downStatus('simple-quote'); |
|
112 | - break; |
|
113 | - } |
|
114 | - break; |
|
115 | - |
|
116 | - case '"': |
|
117 | - switch ($this->status()) { |
|
118 | - case 'double-quote': |
|
119 | - $this->upStatus(); |
|
120 | - break; |
|
121 | - |
|
122 | - case 'line-comment': |
|
123 | - case 'block-comment': |
|
124 | - case 'simple-quote': |
|
125 | - case 'back-tick': |
|
126 | - break; |
|
127 | - |
|
128 | - default: |
|
129 | - $this->downStatus('double-quote'); |
|
130 | - break; |
|
131 | - } |
|
132 | - break; |
|
133 | - |
|
134 | - case '`': |
|
135 | - switch ($this->status()) { |
|
136 | - case 'back-tick': |
|
137 | - $this->upStatus(); |
|
138 | - break; |
|
139 | - |
|
140 | - case 'line-comment': |
|
141 | - case 'block-comment': |
|
142 | - case 'simple-quote': |
|
143 | - case 'double-quote': |
|
144 | - break; |
|
145 | - |
|
146 | - default: |
|
147 | - $this->downStatus('back-tick'); |
|
148 | - break; |
|
149 | - } |
|
150 | - break; |
|
151 | - |
|
152 | - case '(': |
|
153 | - switch ($this->status()) { |
|
154 | - case 'simple-quote': |
|
155 | - case 'double-quote': |
|
156 | - case 'back-tick': |
|
157 | - case 'line-comment': |
|
158 | - case 'block-comment': |
|
159 | - break; |
|
160 | - |
|
161 | - default: |
|
162 | - if ($buffer && preg_match('/(\w+)$/', $buffer, $matches)) { |
|
163 | - $this->downStatus('function'); |
|
164 | - array_unshift($bufferFunctions, [$matches[1], $line, []]); |
|
165 | - $buffer = ''; |
|
166 | - continue 3; |
|
167 | - } |
|
168 | - break; |
|
169 | - } |
|
170 | - break; |
|
171 | - |
|
172 | - case ')': |
|
173 | - switch ($this->status()) { |
|
174 | - case 'function': |
|
175 | - if (($argument = static::prepareArgument($buffer))) { |
|
176 | - $bufferFunctions[0][2][] = $argument; |
|
177 | - } |
|
178 | - |
|
179 | - if (!empty($bufferFunctions)) { |
|
180 | - $functions[] = array_shift($bufferFunctions); |
|
181 | - } |
|
182 | - |
|
183 | - $this->upStatus(); |
|
184 | - $buffer = ''; |
|
185 | - continue 3; |
|
186 | - } |
|
187 | - break; |
|
188 | - |
|
189 | - case ',': |
|
190 | - switch ($this->status()) { |
|
191 | - case 'function': |
|
192 | - if (($argument = static::prepareArgument($buffer))) { |
|
193 | - $bufferFunctions[0][2][] = $argument; |
|
194 | - } |
|
195 | - |
|
196 | - $buffer = ''; |
|
197 | - continue 3; |
|
198 | - } |
|
199 | - break; |
|
200 | - |
|
201 | - case ' ': |
|
202 | - case '\t': |
|
203 | - switch ($this->status()) { |
|
204 | - case 'double-quote': |
|
205 | - case 'simple-quote': |
|
206 | - case 'back-tick': |
|
207 | - break; |
|
208 | - |
|
209 | - default: |
|
210 | - $buffer = ''; |
|
211 | - continue 3; |
|
212 | - } |
|
213 | - break; |
|
214 | - } |
|
215 | - |
|
216 | - switch ($this->status()) { |
|
217 | - case 'line-comment': |
|
218 | - case 'block-comment': |
|
219 | - break; |
|
220 | - |
|
221 | - default: |
|
222 | - $buffer .= $char; |
|
223 | - break; |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - return $functions; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Get the current context of the scan. |
|
232 | - * |
|
233 | - * @param null|string $match To check whether the current status is this value |
|
234 | - * |
|
235 | - * @return string|bool |
|
236 | - */ |
|
237 | - protected function status($match = null) |
|
238 | - { |
|
239 | - $status = isset($this->status[0]) ? $this->status[0] : null; |
|
240 | - |
|
241 | - if ($match !== null) { |
|
242 | - return $status === $match; |
|
243 | - } |
|
244 | - |
|
245 | - return $status; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Add a new status to the stack. |
|
250 | - * |
|
251 | - * @param string $status |
|
252 | - */ |
|
253 | - protected function downStatus($status) |
|
254 | - { |
|
255 | - array_unshift($this->status, $status); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Removes and return the current status. |
|
260 | - * |
|
261 | - * @return string|null |
|
262 | - */ |
|
263 | - protected function upStatus() |
|
264 | - { |
|
265 | - return array_shift($this->status); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Prepares the arguments found in functions. |
|
270 | - * |
|
271 | - * @param string $argument |
|
272 | - * |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - protected static function prepareArgument($argument) |
|
276 | - { |
|
277 | - if ($argument && in_array($argument[0], ['"', "'", '`'], true)) { |
|
278 | - return static::convertString(substr($argument, 1, -1)); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Decodes a string with an argument. |
|
284 | - * |
|
285 | - * @param string $value |
|
286 | - * |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - protected static function convertString($value) |
|
290 | - { |
|
291 | - if (strpos($value, '\\') === false) { |
|
292 | - return $value; |
|
293 | - } |
|
294 | - |
|
295 | - return preg_replace_callback( |
|
296 | - '/\\\(n|r|t|v|e|f|"|\\\)/', |
|
297 | - function ($match) { |
|
298 | - switch ($match[1][0]) { |
|
299 | - case 'n': |
|
300 | - return "\n"; |
|
301 | - case 'r': |
|
302 | - return "\r"; |
|
303 | - case 't': |
|
304 | - return "\t"; |
|
305 | - case 'v': |
|
306 | - return "\v"; |
|
307 | - case 'e': |
|
308 | - return "\e"; |
|
309 | - case 'f': |
|
310 | - return "\f"; |
|
311 | - case '"': |
|
312 | - return '"'; |
|
313 | - case '\\': |
|
314 | - return '\\'; |
|
315 | - } |
|
316 | - }, |
|
317 | - $value |
|
318 | - ); |
|
319 | - } |
|
7 | + protected $code; |
|
8 | + protected $status = []; |
|
9 | + |
|
10 | + /** |
|
11 | + * Constructor. |
|
12 | + * |
|
13 | + * @param string $code The php code to scan |
|
14 | + */ |
|
15 | + public function __construct($code) |
|
16 | + { |
|
17 | + // Normalize newline characters |
|
18 | + $this->code = str_replace(["\r\n", "\n\r", "\r"], "\n", $code); |
|
19 | + } |
|
20 | + |
|
21 | + /** |
|
22 | + * {@inheritdoc} |
|
23 | + */ |
|
24 | + public function getFunctions(array $constants = []) |
|
25 | + { |
|
26 | + $length = strlen($this->code); |
|
27 | + $line = 1; |
|
28 | + $buffer = ''; |
|
29 | + $functions = []; |
|
30 | + $bufferFunctions = []; |
|
31 | + $char = null; |
|
32 | + |
|
33 | + for ($pos = 0; $pos < $length; ++$pos) { |
|
34 | + $prev = $char; |
|
35 | + $char = $this->code[$pos]; |
|
36 | + $next = isset($this->code[$pos + 1]) ? $this->code[$pos + 1] : null; |
|
37 | + |
|
38 | + switch ($char) { |
|
39 | + case '\\': |
|
40 | + switch ($this->status()) { |
|
41 | + case 'simple-quote': |
|
42 | + if ($next !== "'") { |
|
43 | + break 2; |
|
44 | + } |
|
45 | + break; |
|
46 | + |
|
47 | + case 'double-quote': |
|
48 | + if ($next !== '"') { |
|
49 | + break 2; |
|
50 | + } |
|
51 | + break; |
|
52 | + |
|
53 | + case 'back-tick': |
|
54 | + if ($next !== '`') { |
|
55 | + break 2; |
|
56 | + } |
|
57 | + break; |
|
58 | + } |
|
59 | + |
|
60 | + $prev = $char; |
|
61 | + $char = $next; |
|
62 | + $pos++; |
|
63 | + $next = isset($this->code[$pos]) ? $this->code[$pos] : null; |
|
64 | + break; |
|
65 | + |
|
66 | + case "\n": |
|
67 | + ++$line; |
|
68 | + |
|
69 | + if ($this->status('line-comment')) { |
|
70 | + $this->upStatus(); |
|
71 | + } |
|
72 | + break; |
|
73 | + |
|
74 | + case '/': |
|
75 | + switch ($this->status()) { |
|
76 | + case 'simple-quote': |
|
77 | + case 'double-quote': |
|
78 | + case 'back-tick': |
|
79 | + case 'line-comment': |
|
80 | + break; |
|
81 | + |
|
82 | + case 'block-comment': |
|
83 | + if ($prev === '*') { |
|
84 | + $this->upStatus(); |
|
85 | + } |
|
86 | + break; |
|
87 | + |
|
88 | + default: |
|
89 | + if ($next === '/') { |
|
90 | + $this->downStatus('line-comment'); |
|
91 | + } elseif ($next === '*') { |
|
92 | + $this->downStatus('block-comment'); |
|
93 | + } |
|
94 | + break; |
|
95 | + } |
|
96 | + break; |
|
97 | + |
|
98 | + case "'": |
|
99 | + switch ($this->status()) { |
|
100 | + case 'simple-quote': |
|
101 | + $this->upStatus(); |
|
102 | + break; |
|
103 | + |
|
104 | + case 'line-comment': |
|
105 | + case 'block-comment': |
|
106 | + case 'double-quote': |
|
107 | + case 'back-tick': |
|
108 | + break; |
|
109 | + |
|
110 | + default: |
|
111 | + $this->downStatus('simple-quote'); |
|
112 | + break; |
|
113 | + } |
|
114 | + break; |
|
115 | + |
|
116 | + case '"': |
|
117 | + switch ($this->status()) { |
|
118 | + case 'double-quote': |
|
119 | + $this->upStatus(); |
|
120 | + break; |
|
121 | + |
|
122 | + case 'line-comment': |
|
123 | + case 'block-comment': |
|
124 | + case 'simple-quote': |
|
125 | + case 'back-tick': |
|
126 | + break; |
|
127 | + |
|
128 | + default: |
|
129 | + $this->downStatus('double-quote'); |
|
130 | + break; |
|
131 | + } |
|
132 | + break; |
|
133 | + |
|
134 | + case '`': |
|
135 | + switch ($this->status()) { |
|
136 | + case 'back-tick': |
|
137 | + $this->upStatus(); |
|
138 | + break; |
|
139 | + |
|
140 | + case 'line-comment': |
|
141 | + case 'block-comment': |
|
142 | + case 'simple-quote': |
|
143 | + case 'double-quote': |
|
144 | + break; |
|
145 | + |
|
146 | + default: |
|
147 | + $this->downStatus('back-tick'); |
|
148 | + break; |
|
149 | + } |
|
150 | + break; |
|
151 | + |
|
152 | + case '(': |
|
153 | + switch ($this->status()) { |
|
154 | + case 'simple-quote': |
|
155 | + case 'double-quote': |
|
156 | + case 'back-tick': |
|
157 | + case 'line-comment': |
|
158 | + case 'block-comment': |
|
159 | + break; |
|
160 | + |
|
161 | + default: |
|
162 | + if ($buffer && preg_match('/(\w+)$/', $buffer, $matches)) { |
|
163 | + $this->downStatus('function'); |
|
164 | + array_unshift($bufferFunctions, [$matches[1], $line, []]); |
|
165 | + $buffer = ''; |
|
166 | + continue 3; |
|
167 | + } |
|
168 | + break; |
|
169 | + } |
|
170 | + break; |
|
171 | + |
|
172 | + case ')': |
|
173 | + switch ($this->status()) { |
|
174 | + case 'function': |
|
175 | + if (($argument = static::prepareArgument($buffer))) { |
|
176 | + $bufferFunctions[0][2][] = $argument; |
|
177 | + } |
|
178 | + |
|
179 | + if (!empty($bufferFunctions)) { |
|
180 | + $functions[] = array_shift($bufferFunctions); |
|
181 | + } |
|
182 | + |
|
183 | + $this->upStatus(); |
|
184 | + $buffer = ''; |
|
185 | + continue 3; |
|
186 | + } |
|
187 | + break; |
|
188 | + |
|
189 | + case ',': |
|
190 | + switch ($this->status()) { |
|
191 | + case 'function': |
|
192 | + if (($argument = static::prepareArgument($buffer))) { |
|
193 | + $bufferFunctions[0][2][] = $argument; |
|
194 | + } |
|
195 | + |
|
196 | + $buffer = ''; |
|
197 | + continue 3; |
|
198 | + } |
|
199 | + break; |
|
200 | + |
|
201 | + case ' ': |
|
202 | + case '\t': |
|
203 | + switch ($this->status()) { |
|
204 | + case 'double-quote': |
|
205 | + case 'simple-quote': |
|
206 | + case 'back-tick': |
|
207 | + break; |
|
208 | + |
|
209 | + default: |
|
210 | + $buffer = ''; |
|
211 | + continue 3; |
|
212 | + } |
|
213 | + break; |
|
214 | + } |
|
215 | + |
|
216 | + switch ($this->status()) { |
|
217 | + case 'line-comment': |
|
218 | + case 'block-comment': |
|
219 | + break; |
|
220 | + |
|
221 | + default: |
|
222 | + $buffer .= $char; |
|
223 | + break; |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + return $functions; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Get the current context of the scan. |
|
232 | + * |
|
233 | + * @param null|string $match To check whether the current status is this value |
|
234 | + * |
|
235 | + * @return string|bool |
|
236 | + */ |
|
237 | + protected function status($match = null) |
|
238 | + { |
|
239 | + $status = isset($this->status[0]) ? $this->status[0] : null; |
|
240 | + |
|
241 | + if ($match !== null) { |
|
242 | + return $status === $match; |
|
243 | + } |
|
244 | + |
|
245 | + return $status; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Add a new status to the stack. |
|
250 | + * |
|
251 | + * @param string $status |
|
252 | + */ |
|
253 | + protected function downStatus($status) |
|
254 | + { |
|
255 | + array_unshift($this->status, $status); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Removes and return the current status. |
|
260 | + * |
|
261 | + * @return string|null |
|
262 | + */ |
|
263 | + protected function upStatus() |
|
264 | + { |
|
265 | + return array_shift($this->status); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Prepares the arguments found in functions. |
|
270 | + * |
|
271 | + * @param string $argument |
|
272 | + * |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + protected static function prepareArgument($argument) |
|
276 | + { |
|
277 | + if ($argument && in_array($argument[0], ['"', "'", '`'], true)) { |
|
278 | + return static::convertString(substr($argument, 1, -1)); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Decodes a string with an argument. |
|
284 | + * |
|
285 | + * @param string $value |
|
286 | + * |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + protected static function convertString($value) |
|
290 | + { |
|
291 | + if (strpos($value, '\\') === false) { |
|
292 | + return $value; |
|
293 | + } |
|
294 | + |
|
295 | + return preg_replace_callback( |
|
296 | + '/\\\(n|r|t|v|e|f|"|\\\)/', |
|
297 | + function ($match) { |
|
298 | + switch ($match[1][0]) { |
|
299 | + case 'n': |
|
300 | + return "\n"; |
|
301 | + case 'r': |
|
302 | + return "\r"; |
|
303 | + case 't': |
|
304 | + return "\t"; |
|
305 | + case 'v': |
|
306 | + return "\v"; |
|
307 | + case 'e': |
|
308 | + return "\e"; |
|
309 | + case 'f': |
|
310 | + return "\f"; |
|
311 | + case '"': |
|
312 | + return '"'; |
|
313 | + case '\\': |
|
314 | + return '\\'; |
|
315 | + } |
|
316 | + }, |
|
317 | + $value |
|
318 | + ); |
|
319 | + } |
|
320 | 320 | } |
@@ -5,53 +5,53 @@ discard block |
||
5 | 5 | class JsFunctionsScanner extends FunctionsScanner |
6 | 6 | { |
7 | 7 | protected $code; |
8 | - protected $status = []; |
|
8 | + protected $status = [ ]; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Constructor. |
12 | 12 | * |
13 | 13 | * @param string $code The php code to scan |
14 | 14 | */ |
15 | - public function __construct($code) |
|
15 | + public function __construct( $code ) |
|
16 | 16 | { |
17 | 17 | // Normalize newline characters |
18 | - $this->code = str_replace(["\r\n", "\n\r", "\r"], "\n", $code); |
|
18 | + $this->code = str_replace( [ "\r\n", "\n\r", "\r" ], "\n", $code ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * {@inheritdoc} |
23 | 23 | */ |
24 | - public function getFunctions(array $constants = []) |
|
24 | + public function getFunctions( array $constants = [ ] ) |
|
25 | 25 | { |
26 | - $length = strlen($this->code); |
|
26 | + $length = strlen( $this->code ); |
|
27 | 27 | $line = 1; |
28 | 28 | $buffer = ''; |
29 | - $functions = []; |
|
30 | - $bufferFunctions = []; |
|
29 | + $functions = [ ]; |
|
30 | + $bufferFunctions = [ ]; |
|
31 | 31 | $char = null; |
32 | 32 | |
33 | - for ($pos = 0; $pos < $length; ++$pos) { |
|
33 | + for ( $pos = 0; $pos < $length; ++$pos ) { |
|
34 | 34 | $prev = $char; |
35 | - $char = $this->code[$pos]; |
|
36 | - $next = isset($this->code[$pos + 1]) ? $this->code[$pos + 1] : null; |
|
35 | + $char = $this->code[ $pos ]; |
|
36 | + $next = isset( $this->code[ $pos + 1 ] ) ? $this->code[ $pos + 1 ] : null; |
|
37 | 37 | |
38 | - switch ($char) { |
|
38 | + switch ( $char ) { |
|
39 | 39 | case '\\': |
40 | - switch ($this->status()) { |
|
40 | + switch ( $this->status() ) { |
|
41 | 41 | case 'simple-quote': |
42 | - if ($next !== "'") { |
|
42 | + if ( $next !== "'" ) { |
|
43 | 43 | break 2; |
44 | 44 | } |
45 | 45 | break; |
46 | 46 | |
47 | 47 | case 'double-quote': |
48 | - if ($next !== '"') { |
|
48 | + if ( $next !== '"' ) { |
|
49 | 49 | break 2; |
50 | 50 | } |
51 | 51 | break; |
52 | 52 | |
53 | 53 | case 'back-tick': |
54 | - if ($next !== '`') { |
|
54 | + if ( $next !== '`' ) { |
|
55 | 55 | break 2; |
56 | 56 | } |
57 | 57 | break; |
@@ -60,19 +60,19 @@ discard block |
||
60 | 60 | $prev = $char; |
61 | 61 | $char = $next; |
62 | 62 | $pos++; |
63 | - $next = isset($this->code[$pos]) ? $this->code[$pos] : null; |
|
63 | + $next = isset( $this->code[ $pos ] ) ? $this->code[ $pos ] : null; |
|
64 | 64 | break; |
65 | 65 | |
66 | 66 | case "\n": |
67 | 67 | ++$line; |
68 | 68 | |
69 | - if ($this->status('line-comment')) { |
|
69 | + if ( $this->status( 'line-comment' ) ) { |
|
70 | 70 | $this->upStatus(); |
71 | 71 | } |
72 | 72 | break; |
73 | 73 | |
74 | 74 | case '/': |
75 | - switch ($this->status()) { |
|
75 | + switch ( $this->status() ) { |
|
76 | 76 | case 'simple-quote': |
77 | 77 | case 'double-quote': |
78 | 78 | case 'back-tick': |
@@ -80,23 +80,23 @@ discard block |
||
80 | 80 | break; |
81 | 81 | |
82 | 82 | case 'block-comment': |
83 | - if ($prev === '*') { |
|
83 | + if ( $prev === '*' ) { |
|
84 | 84 | $this->upStatus(); |
85 | 85 | } |
86 | 86 | break; |
87 | 87 | |
88 | 88 | default: |
89 | - if ($next === '/') { |
|
90 | - $this->downStatus('line-comment'); |
|
91 | - } elseif ($next === '*') { |
|
92 | - $this->downStatus('block-comment'); |
|
89 | + if ( $next === '/' ) { |
|
90 | + $this->downStatus( 'line-comment' ); |
|
91 | + } elseif ( $next === '*' ) { |
|
92 | + $this->downStatus( 'block-comment' ); |
|
93 | 93 | } |
94 | 94 | break; |
95 | 95 | } |
96 | 96 | break; |
97 | 97 | |
98 | 98 | case "'": |
99 | - switch ($this->status()) { |
|
99 | + switch ( $this->status() ) { |
|
100 | 100 | case 'simple-quote': |
101 | 101 | $this->upStatus(); |
102 | 102 | break; |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | break; |
109 | 109 | |
110 | 110 | default: |
111 | - $this->downStatus('simple-quote'); |
|
111 | + $this->downStatus( 'simple-quote' ); |
|
112 | 112 | break; |
113 | 113 | } |
114 | 114 | break; |
115 | 115 | |
116 | 116 | case '"': |
117 | - switch ($this->status()) { |
|
117 | + switch ( $this->status() ) { |
|
118 | 118 | case 'double-quote': |
119 | 119 | $this->upStatus(); |
120 | 120 | break; |
@@ -126,13 +126,13 @@ discard block |
||
126 | 126 | break; |
127 | 127 | |
128 | 128 | default: |
129 | - $this->downStatus('double-quote'); |
|
129 | + $this->downStatus( 'double-quote' ); |
|
130 | 130 | break; |
131 | 131 | } |
132 | 132 | break; |
133 | 133 | |
134 | 134 | case '`': |
135 | - switch ($this->status()) { |
|
135 | + switch ( $this->status() ) { |
|
136 | 136 | case 'back-tick': |
137 | 137 | $this->upStatus(); |
138 | 138 | break; |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | break; |
145 | 145 | |
146 | 146 | default: |
147 | - $this->downStatus('back-tick'); |
|
147 | + $this->downStatus( 'back-tick' ); |
|
148 | 148 | break; |
149 | 149 | } |
150 | 150 | break; |
151 | 151 | |
152 | 152 | case '(': |
153 | - switch ($this->status()) { |
|
153 | + switch ( $this->status() ) { |
|
154 | 154 | case 'simple-quote': |
155 | 155 | case 'double-quote': |
156 | 156 | case 'back-tick': |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | break; |
160 | 160 | |
161 | 161 | default: |
162 | - if ($buffer && preg_match('/(\w+)$/', $buffer, $matches)) { |
|
163 | - $this->downStatus('function'); |
|
164 | - array_unshift($bufferFunctions, [$matches[1], $line, []]); |
|
162 | + if ( $buffer && preg_match( '/(\w+)$/', $buffer, $matches ) ) { |
|
163 | + $this->downStatus( 'function' ); |
|
164 | + array_unshift( $bufferFunctions, [ $matches[ 1 ], $line, [ ] ] ); |
|
165 | 165 | $buffer = ''; |
166 | 166 | continue 3; |
167 | 167 | } |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | break; |
171 | 171 | |
172 | 172 | case ')': |
173 | - switch ($this->status()) { |
|
173 | + switch ( $this->status() ) { |
|
174 | 174 | case 'function': |
175 | - if (($argument = static::prepareArgument($buffer))) { |
|
176 | - $bufferFunctions[0][2][] = $argument; |
|
175 | + if ( ( $argument = static::prepareArgument( $buffer ) ) ) { |
|
176 | + $bufferFunctions[ 0 ][ 2 ][ ] = $argument; |
|
177 | 177 | } |
178 | 178 | |
179 | - if (!empty($bufferFunctions)) { |
|
180 | - $functions[] = array_shift($bufferFunctions); |
|
179 | + if ( ! empty( $bufferFunctions ) ) { |
|
180 | + $functions[ ] = array_shift( $bufferFunctions ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | $this->upStatus(); |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | break; |
188 | 188 | |
189 | 189 | case ',': |
190 | - switch ($this->status()) { |
|
190 | + switch ( $this->status() ) { |
|
191 | 191 | case 'function': |
192 | - if (($argument = static::prepareArgument($buffer))) { |
|
193 | - $bufferFunctions[0][2][] = $argument; |
|
192 | + if ( ( $argument = static::prepareArgument( $buffer ) ) ) { |
|
193 | + $bufferFunctions[ 0 ][ 2 ][ ] = $argument; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | $buffer = ''; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | case ' ': |
202 | 202 | case '\t': |
203 | - switch ($this->status()) { |
|
203 | + switch ( $this->status() ) { |
|
204 | 204 | case 'double-quote': |
205 | 205 | case 'simple-quote': |
206 | 206 | case 'back-tick': |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | break; |
214 | 214 | } |
215 | 215 | |
216 | - switch ($this->status()) { |
|
216 | + switch ( $this->status() ) { |
|
217 | 217 | case 'line-comment': |
218 | 218 | case 'block-comment': |
219 | 219 | break; |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return string|bool |
236 | 236 | */ |
237 | - protected function status($match = null) |
|
237 | + protected function status( $match = null ) |
|
238 | 238 | { |
239 | - $status = isset($this->status[0]) ? $this->status[0] : null; |
|
239 | + $status = isset( $this->status[ 0 ] ) ? $this->status[ 0 ] : null; |
|
240 | 240 | |
241 | - if ($match !== null) { |
|
241 | + if ( $match !== null ) { |
|
242 | 242 | return $status === $match; |
243 | 243 | } |
244 | 244 | |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @param string $status |
252 | 252 | */ |
253 | - protected function downStatus($status) |
|
253 | + protected function downStatus( $status ) |
|
254 | 254 | { |
255 | - array_unshift($this->status, $status); |
|
255 | + array_unshift( $this->status, $status ); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | protected function upStatus() |
264 | 264 | { |
265 | - return array_shift($this->status); |
|
265 | + return array_shift( $this->status ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return string |
274 | 274 | */ |
275 | - protected static function prepareArgument($argument) |
|
275 | + protected static function prepareArgument( $argument ) |
|
276 | 276 | { |
277 | - if ($argument && in_array($argument[0], ['"', "'", '`'], true)) { |
|
278 | - return static::convertString(substr($argument, 1, -1)); |
|
277 | + if ( $argument && in_array( $argument[ 0 ], [ '"', "'", '`' ], true ) ) { |
|
278 | + return static::convertString( substr( $argument, 1, -1 ) ); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
@@ -286,16 +286,16 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return string |
288 | 288 | */ |
289 | - protected static function convertString($value) |
|
289 | + protected static function convertString( $value ) |
|
290 | 290 | { |
291 | - if (strpos($value, '\\') === false) { |
|
291 | + if ( strpos( $value, '\\' ) === false ) { |
|
292 | 292 | return $value; |
293 | 293 | } |
294 | 294 | |
295 | 295 | return preg_replace_callback( |
296 | 296 | '/\\\(n|r|t|v|e|f|"|\\\)/', |
297 | - function ($match) { |
|
298 | - switch ($match[1][0]) { |
|
297 | + function( $match ) { |
|
298 | + switch ( $match[ 1 ][ 0 ] ) { |
|
299 | 299 | case 'n': |
300 | 300 | return "\n"; |
301 | 301 | case 'r': |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Utils; |
4 | 4 | |
5 | -class JsFunctionsScanner extends FunctionsScanner |
|
6 | -{ |
|
5 | +class JsFunctionsScanner extends FunctionsScanner { |
|
7 | 6 | protected $code; |
8 | 7 | protected $status = []; |
9 | 8 | |
@@ -12,8 +11,7 @@ discard block |
||
12 | 11 | * |
13 | 12 | * @param string $code The php code to scan |
14 | 13 | */ |
15 | - public function __construct($code) |
|
16 | - { |
|
14 | + public function __construct($code) { |
|
17 | 15 | // Normalize newline characters |
18 | 16 | $this->code = str_replace(["\r\n", "\n\r", "\r"], "\n", $code); |
19 | 17 | } |
@@ -21,8 +19,7 @@ discard block |
||
21 | 19 | /** |
22 | 20 | * {@inheritdoc} |
23 | 21 | */ |
24 | - public function getFunctions(array $constants = []) |
|
25 | - { |
|
22 | + public function getFunctions(array $constants = []) { |
|
26 | 23 | $length = strlen($this->code); |
27 | 24 | $line = 1; |
28 | 25 | $buffer = ''; |
@@ -234,8 +231,7 @@ discard block |
||
234 | 231 | * |
235 | 232 | * @return string|bool |
236 | 233 | */ |
237 | - protected function status($match = null) |
|
238 | - { |
|
234 | + protected function status($match = null) { |
|
239 | 235 | $status = isset($this->status[0]) ? $this->status[0] : null; |
240 | 236 | |
241 | 237 | if ($match !== null) { |
@@ -250,8 +246,7 @@ discard block |
||
250 | 246 | * |
251 | 247 | * @param string $status |
252 | 248 | */ |
253 | - protected function downStatus($status) |
|
254 | - { |
|
249 | + protected function downStatus($status) { |
|
255 | 250 | array_unshift($this->status, $status); |
256 | 251 | } |
257 | 252 | |
@@ -260,8 +255,7 @@ discard block |
||
260 | 255 | * |
261 | 256 | * @return string|null |
262 | 257 | */ |
263 | - protected function upStatus() |
|
264 | - { |
|
258 | + protected function upStatus() { |
|
265 | 259 | return array_shift($this->status); |
266 | 260 | } |
267 | 261 | |
@@ -272,8 +266,7 @@ discard block |
||
272 | 266 | * |
273 | 267 | * @return string |
274 | 268 | */ |
275 | - protected static function prepareArgument($argument) |
|
276 | - { |
|
269 | + protected static function prepareArgument($argument) { |
|
277 | 270 | if ($argument && in_array($argument[0], ['"', "'", '`'], true)) { |
278 | 271 | return static::convertString(substr($argument, 1, -1)); |
279 | 272 | } |
@@ -286,8 +279,7 @@ discard block |
||
286 | 279 | * |
287 | 280 | * @return string |
288 | 281 | */ |
289 | - protected static function convertString($value) |
|
290 | - { |
|
282 | + protected static function convertString($value) { |
|
291 | 283 | if (strpos($value, '\\') === false) { |
292 | 284 | return $value; |
293 | 285 | } |
@@ -7,50 +7,50 @@ |
||
7 | 7 | */ |
8 | 8 | trait CsvTrait |
9 | 9 | { |
10 | - protected static $csvEscapeChar; |
|
11 | - |
|
12 | - /** |
|
13 | - * Check whether support the escape_char argument to fgetcsv/fputcsv or not |
|
14 | - * |
|
15 | - * @return bool |
|
16 | - */ |
|
17 | - protected static function supportsCsvEscapeChar() |
|
18 | - { |
|
19 | - if (static::$csvEscapeChar === null) { |
|
20 | - static::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0; |
|
21 | - } |
|
22 | - |
|
23 | - return static::$csvEscapeChar; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * @param resource $handle |
|
28 | - * @param array $options |
|
29 | - * |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - protected static function fgetcsv($handle, $options) |
|
33 | - { |
|
34 | - if (static::supportsCsvEscapeChar()) { |
|
35 | - return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
|
36 | - } |
|
37 | - |
|
38 | - return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure']); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param resource $handle |
|
43 | - * @param array $fields |
|
44 | - * @param array $options |
|
45 | - * |
|
46 | - * @return bool|int |
|
47 | - */ |
|
48 | - protected static function fputcsv($handle, $fields, $options) |
|
49 | - { |
|
50 | - if (static::supportsCsvEscapeChar()) { |
|
51 | - return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
|
52 | - } |
|
53 | - |
|
54 | - return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure']); |
|
55 | - } |
|
10 | + protected static $csvEscapeChar; |
|
11 | + |
|
12 | + /** |
|
13 | + * Check whether support the escape_char argument to fgetcsv/fputcsv or not |
|
14 | + * |
|
15 | + * @return bool |
|
16 | + */ |
|
17 | + protected static function supportsCsvEscapeChar() |
|
18 | + { |
|
19 | + if (static::$csvEscapeChar === null) { |
|
20 | + static::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0; |
|
21 | + } |
|
22 | + |
|
23 | + return static::$csvEscapeChar; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * @param resource $handle |
|
28 | + * @param array $options |
|
29 | + * |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + protected static function fgetcsv($handle, $options) |
|
33 | + { |
|
34 | + if (static::supportsCsvEscapeChar()) { |
|
35 | + return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
|
36 | + } |
|
37 | + |
|
38 | + return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure']); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param resource $handle |
|
43 | + * @param array $fields |
|
44 | + * @param array $options |
|
45 | + * |
|
46 | + * @return bool|int |
|
47 | + */ |
|
48 | + protected static function fputcsv($handle, $fields, $options) |
|
49 | + { |
|
50 | + if (static::supportsCsvEscapeChar()) { |
|
51 | + return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
|
52 | + } |
|
53 | + |
|
54 | + return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure']); |
|
55 | + } |
|
56 | 56 | } |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected static function supportsCsvEscapeChar() |
18 | 18 | { |
19 | - if (static::$csvEscapeChar === null) { |
|
20 | - static::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0; |
|
19 | + if ( static::$csvEscapeChar === null ) { |
|
20 | + static::$csvEscapeChar = version_compare( PHP_VERSION, '5.5.4' ) >= 0; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | return static::$csvEscapeChar; |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - protected static function fgetcsv($handle, $options) |
|
32 | + protected static function fgetcsv( $handle, $options ) |
|
33 | 33 | { |
34 | - if (static::supportsCsvEscapeChar()) { |
|
35 | - return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
|
34 | + if ( static::supportsCsvEscapeChar() ) { |
|
35 | + return fgetcsv( $handle, 0, $options[ 'delimiter' ], $options[ 'enclosure' ], $options[ 'escape_char' ] ); |
|
36 | 36 | } |
37 | 37 | |
38 | - return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure']); |
|
38 | + return fgetcsv( $handle, 0, $options[ 'delimiter' ], $options[ 'enclosure' ] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return bool|int |
47 | 47 | */ |
48 | - protected static function fputcsv($handle, $fields, $options) |
|
48 | + protected static function fputcsv( $handle, $fields, $options ) |
|
49 | 49 | { |
50 | - if (static::supportsCsvEscapeChar()) { |
|
51 | - return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
|
50 | + if ( static::supportsCsvEscapeChar() ) { |
|
51 | + return fputcsv( $handle, $fields, $options[ 'delimiter' ], $options[ 'enclosure' ], $options[ 'escape_char' ] ); |
|
52 | 52 | } |
53 | 53 | |
54 | - return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure']); |
|
54 | + return fputcsv( $handle, $fields, $options[ 'delimiter' ], $options[ 'enclosure' ] ); |
|
55 | 55 | } |
56 | 56 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | /* |
6 | 6 | * Trait to provide the functionality of read/write csv. |
7 | 7 | */ |
8 | -trait CsvTrait |
|
9 | -{ |
|
8 | +trait CsvTrait { |
|
10 | 9 | protected static $csvEscapeChar; |
11 | 10 | |
12 | 11 | /** |
@@ -14,8 +13,7 @@ discard block |
||
14 | 13 | * |
15 | 14 | * @return bool |
16 | 15 | */ |
17 | - protected static function supportsCsvEscapeChar() |
|
18 | - { |
|
16 | + protected static function supportsCsvEscapeChar() { |
|
19 | 17 | if (static::$csvEscapeChar === null) { |
20 | 18 | static::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0; |
21 | 19 | } |
@@ -29,8 +27,7 @@ discard block |
||
29 | 27 | * |
30 | 28 | * @return array |
31 | 29 | */ |
32 | - protected static function fgetcsv($handle, $options) |
|
33 | - { |
|
30 | + protected static function fgetcsv($handle, $options) { |
|
34 | 31 | if (static::supportsCsvEscapeChar()) { |
35 | 32 | return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
36 | 33 | } |
@@ -45,8 +42,7 @@ discard block |
||
45 | 42 | * |
46 | 43 | * @return bool|int |
47 | 44 | */ |
48 | - protected static function fputcsv($handle, $fields, $options) |
|
49 | - { |
|
45 | + protected static function fputcsv($handle, $fields, $options) { |
|
50 | 46 | if (static::supportsCsvEscapeChar()) { |
51 | 47 | return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
52 | 48 | } |
@@ -4,48 +4,48 @@ |
||
4 | 4 | |
5 | 5 | class StringReader |
6 | 6 | { |
7 | - public $pos; |
|
8 | - public $str; |
|
9 | - public $strlen; |
|
10 | - |
|
11 | - /** |
|
12 | - * Constructor. |
|
13 | - * |
|
14 | - * @param string $str The string to read |
|
15 | - */ |
|
16 | - public function __construct($str) |
|
17 | - { |
|
18 | - $this->str = $str; |
|
19 | - $this->strlen = strlen($this->str); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * Read and returns a part of the string. |
|
24 | - * |
|
25 | - * @param int $bytes The number of bytes to read |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function read($bytes) |
|
30 | - { |
|
31 | - $data = substr($this->str, $this->pos, $bytes); |
|
32 | - |
|
33 | - $this->seekto($this->pos + $bytes); |
|
34 | - |
|
35 | - return $data; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Move the cursor to a specific position. |
|
40 | - * |
|
41 | - * @param int $pos The amount of bytes to move |
|
42 | - * |
|
43 | - * @return int The new position |
|
44 | - */ |
|
45 | - public function seekto($pos) |
|
46 | - { |
|
47 | - $this->pos = ($this->strlen < $pos) ? $this->strlen : $pos; |
|
48 | - |
|
49 | - return $this->pos; |
|
50 | - } |
|
7 | + public $pos; |
|
8 | + public $str; |
|
9 | + public $strlen; |
|
10 | + |
|
11 | + /** |
|
12 | + * Constructor. |
|
13 | + * |
|
14 | + * @param string $str The string to read |
|
15 | + */ |
|
16 | + public function __construct($str) |
|
17 | + { |
|
18 | + $this->str = $str; |
|
19 | + $this->strlen = strlen($this->str); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * Read and returns a part of the string. |
|
24 | + * |
|
25 | + * @param int $bytes The number of bytes to read |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function read($bytes) |
|
30 | + { |
|
31 | + $data = substr($this->str, $this->pos, $bytes); |
|
32 | + |
|
33 | + $this->seekto($this->pos + $bytes); |
|
34 | + |
|
35 | + return $data; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Move the cursor to a specific position. |
|
40 | + * |
|
41 | + * @param int $pos The amount of bytes to move |
|
42 | + * |
|
43 | + * @return int The new position |
|
44 | + */ |
|
45 | + public function seekto($pos) |
|
46 | + { |
|
47 | + $this->pos = ($this->strlen < $pos) ? $this->strlen : $pos; |
|
48 | + |
|
49 | + return $this->pos; |
|
50 | + } |
|
51 | 51 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @param string $str The string to read |
15 | 15 | */ |
16 | - public function __construct($str) |
|
16 | + public function __construct( $str ) |
|
17 | 17 | { |
18 | 18 | $this->str = $str; |
19 | - $this->strlen = strlen($this->str); |
|
19 | + $this->strlen = strlen( $this->str ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function read($bytes) |
|
29 | + public function read( $bytes ) |
|
30 | 30 | { |
31 | - $data = substr($this->str, $this->pos, $bytes); |
|
31 | + $data = substr( $this->str, $this->pos, $bytes ); |
|
32 | 32 | |
33 | - $this->seekto($this->pos + $bytes); |
|
33 | + $this->seekto( $this->pos + $bytes ); |
|
34 | 34 | |
35 | 35 | return $data; |
36 | 36 | } |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return int The new position |
44 | 44 | */ |
45 | - public function seekto($pos) |
|
45 | + public function seekto( $pos ) |
|
46 | 46 | { |
47 | - $this->pos = ($this->strlen < $pos) ? $this->strlen : $pos; |
|
47 | + $this->pos = ( $this->strlen < $pos ) ? $this->strlen : $pos; |
|
48 | 48 | |
49 | 49 | return $this->pos; |
50 | 50 | } |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Utils; |
4 | 4 | |
5 | -class StringReader |
|
6 | -{ |
|
5 | +class StringReader { |
|
7 | 6 | public $pos; |
8 | 7 | public $str; |
9 | 8 | public $strlen; |
@@ -13,8 +12,7 @@ discard block |
||
13 | 12 | * |
14 | 13 | * @param string $str The string to read |
15 | 14 | */ |
16 | - public function __construct($str) |
|
17 | - { |
|
15 | + public function __construct($str) { |
|
18 | 16 | $this->str = $str; |
19 | 17 | $this->strlen = strlen($this->str); |
20 | 18 | } |
@@ -26,8 +24,7 @@ discard block |
||
26 | 24 | * |
27 | 25 | * @return string |
28 | 26 | */ |
29 | - public function read($bytes) |
|
30 | - { |
|
27 | + public function read($bytes) { |
|
31 | 28 | $data = substr($this->str, $this->pos, $bytes); |
32 | 29 | |
33 | 30 | $this->seekto($this->pos + $bytes); |
@@ -42,8 +39,7 @@ discard block |
||
42 | 39 | * |
43 | 40 | * @return int The new position |
44 | 41 | */ |
45 | - public function seekto($pos) |
|
46 | - { |
|
42 | + public function seekto($pos) { |
|
47 | 43 | $this->pos = ($this->strlen < $pos) ? $this->strlen : $pos; |
48 | 44 | |
49 | 45 | return $this->pos; |
@@ -7,153 +7,153 @@ |
||
7 | 7 | */ |
8 | 8 | class ParsedFunction |
9 | 9 | { |
10 | - /** |
|
11 | - * The function name. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $name; |
|
10 | + /** |
|
11 | + * The function name. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $name; |
|
16 | 16 | |
17 | - /** |
|
18 | - * The line where the function starts. |
|
19 | - * |
|
20 | - * @var int |
|
21 | - */ |
|
22 | - protected $line; |
|
17 | + /** |
|
18 | + * The line where the function starts. |
|
19 | + * |
|
20 | + * @var int |
|
21 | + */ |
|
22 | + protected $line; |
|
23 | 23 | |
24 | - /** |
|
25 | - * The strings extracted from the function arguments. |
|
26 | - * |
|
27 | - * @var string[] |
|
28 | - */ |
|
29 | - protected $arguments; |
|
24 | + /** |
|
25 | + * The strings extracted from the function arguments. |
|
26 | + * |
|
27 | + * @var string[] |
|
28 | + */ |
|
29 | + protected $arguments; |
|
30 | 30 | |
31 | - /** |
|
32 | - * The current index of the function (-1 if no arguments). |
|
33 | - * |
|
34 | - * @var int|null |
|
35 | - */ |
|
36 | - protected $argumentIndex; |
|
31 | + /** |
|
32 | + * The current index of the function (-1 if no arguments). |
|
33 | + * |
|
34 | + * @var int|null |
|
35 | + */ |
|
36 | + protected $argumentIndex; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Shall we stop adding string chunks to the current argument? |
|
40 | - * |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - protected $argumentStopped; |
|
38 | + /** |
|
39 | + * Shall we stop adding string chunks to the current argument? |
|
40 | + * |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + protected $argumentStopped; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Extracted comments. |
|
47 | - * |
|
48 | - * @var ParsedComment[]|null |
|
49 | - */ |
|
50 | - protected $comments; |
|
45 | + /** |
|
46 | + * Extracted comments. |
|
47 | + * |
|
48 | + * @var ParsedComment[]|null |
|
49 | + */ |
|
50 | + protected $comments; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Initializes the instance. |
|
54 | - * |
|
55 | - * @param string $name The function name. |
|
56 | - * @param int $line The line where the function starts. |
|
57 | - */ |
|
58 | - public function __construct($name, $line) |
|
59 | - { |
|
60 | - $this->name = $name; |
|
61 | - $this->line = $line; |
|
62 | - $this->arguments = []; |
|
63 | - $this->argumentIndex = -1; |
|
64 | - $this->argumentStopped = false; |
|
65 | - $this->comments = null; |
|
66 | - } |
|
52 | + /** |
|
53 | + * Initializes the instance. |
|
54 | + * |
|
55 | + * @param string $name The function name. |
|
56 | + * @param int $line The line where the function starts. |
|
57 | + */ |
|
58 | + public function __construct($name, $line) |
|
59 | + { |
|
60 | + $this->name = $name; |
|
61 | + $this->line = $line; |
|
62 | + $this->arguments = []; |
|
63 | + $this->argumentIndex = -1; |
|
64 | + $this->argumentStopped = false; |
|
65 | + $this->comments = null; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Stop extracting strings from the current argument (because we found something that's not a string). |
|
70 | - */ |
|
71 | - public function stopArgument() |
|
72 | - { |
|
73 | - if ($this->argumentIndex === -1) { |
|
74 | - $this->argumentIndex = 0; |
|
75 | - } |
|
76 | - $this->argumentStopped = true; |
|
77 | - } |
|
68 | + /** |
|
69 | + * Stop extracting strings from the current argument (because we found something that's not a string). |
|
70 | + */ |
|
71 | + public function stopArgument() |
|
72 | + { |
|
73 | + if ($this->argumentIndex === -1) { |
|
74 | + $this->argumentIndex = 0; |
|
75 | + } |
|
76 | + $this->argumentStopped = true; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Go to the next argument because we a comma was found. |
|
81 | - */ |
|
82 | - public function nextArgument() |
|
83 | - { |
|
84 | - if ($this->argumentIndex === -1) { |
|
85 | - // This should neve occur, but let's stay safe - During test/development an Exception should be thrown. |
|
86 | - $this->argumentIndex = 1; |
|
87 | - } else { |
|
88 | - ++$this->argumentIndex; |
|
89 | - } |
|
90 | - $this->argumentStopped = false; |
|
91 | - } |
|
79 | + /** |
|
80 | + * Go to the next argument because we a comma was found. |
|
81 | + */ |
|
82 | + public function nextArgument() |
|
83 | + { |
|
84 | + if ($this->argumentIndex === -1) { |
|
85 | + // This should neve occur, but let's stay safe - During test/development an Exception should be thrown. |
|
86 | + $this->argumentIndex = 1; |
|
87 | + } else { |
|
88 | + ++$this->argumentIndex; |
|
89 | + } |
|
90 | + $this->argumentStopped = false; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Add a string to the current argument. |
|
95 | - * |
|
96 | - * @param string|null $chunk |
|
97 | - */ |
|
98 | - public function addArgumentChunk($chunk) |
|
99 | - { |
|
100 | - if ($this->argumentStopped === false) { |
|
101 | - if ($this->argumentIndex === -1) { |
|
102 | - $this->argumentIndex = 0; |
|
103 | - } |
|
104 | - if (isset($this->arguments[$this->argumentIndex])) { |
|
105 | - $this->arguments[$this->argumentIndex] .= $chunk; |
|
106 | - } else { |
|
107 | - $this->arguments[$this->argumentIndex] = $chunk; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
93 | + /** |
|
94 | + * Add a string to the current argument. |
|
95 | + * |
|
96 | + * @param string|null $chunk |
|
97 | + */ |
|
98 | + public function addArgumentChunk($chunk) |
|
99 | + { |
|
100 | + if ($this->argumentStopped === false) { |
|
101 | + if ($this->argumentIndex === -1) { |
|
102 | + $this->argumentIndex = 0; |
|
103 | + } |
|
104 | + if (isset($this->arguments[$this->argumentIndex])) { |
|
105 | + $this->arguments[$this->argumentIndex] .= $chunk; |
|
106 | + } else { |
|
107 | + $this->arguments[$this->argumentIndex] = $chunk; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Add a comment associated to this function. |
|
114 | - * |
|
115 | - * @param ParsedComment $comment |
|
116 | - */ |
|
117 | - public function addComment($comment) |
|
118 | - { |
|
119 | - if ($this->comments === null) { |
|
120 | - $this->comments = []; |
|
121 | - } |
|
122 | - $this->comments[] = $comment; |
|
123 | - } |
|
112 | + /** |
|
113 | + * Add a comment associated to this function. |
|
114 | + * |
|
115 | + * @param ParsedComment $comment |
|
116 | + */ |
|
117 | + public function addComment($comment) |
|
118 | + { |
|
119 | + if ($this->comments === null) { |
|
120 | + $this->comments = []; |
|
121 | + } |
|
122 | + $this->comments[] = $comment; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Return the line the function starts. |
|
127 | - * |
|
128 | - * @return int Line number. |
|
129 | - */ |
|
130 | - public function getLine() |
|
131 | - { |
|
132 | - return $this->line; |
|
133 | - } |
|
125 | + /** |
|
126 | + * Return the line the function starts. |
|
127 | + * |
|
128 | + * @return int Line number. |
|
129 | + */ |
|
130 | + public function getLine() |
|
131 | + { |
|
132 | + return $this->line; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * A closing parenthesis was found: return the final data. |
|
137 | - * The array returned has the following values: |
|
138 | - * 0 => string The function name. |
|
139 | - * 1 => int The line where the function starts. |
|
140 | - * 2 => string[] the strings extracted from the function arguments. |
|
141 | - * 3 => string[] the comments associated to the function. |
|
142 | - * |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function close() |
|
146 | - { |
|
147 | - $arguments = []; |
|
148 | - for ($i = 0; $i <= $this->argumentIndex; ++$i) { |
|
149 | - $arguments[$i] = isset($this->arguments[$i]) ? $this->arguments[$i] : null; |
|
150 | - } |
|
135 | + /** |
|
136 | + * A closing parenthesis was found: return the final data. |
|
137 | + * The array returned has the following values: |
|
138 | + * 0 => string The function name. |
|
139 | + * 1 => int The line where the function starts. |
|
140 | + * 2 => string[] the strings extracted from the function arguments. |
|
141 | + * 3 => string[] the comments associated to the function. |
|
142 | + * |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function close() |
|
146 | + { |
|
147 | + $arguments = []; |
|
148 | + for ($i = 0; $i <= $this->argumentIndex; ++$i) { |
|
149 | + $arguments[$i] = isset($this->arguments[$i]) ? $this->arguments[$i] : null; |
|
150 | + } |
|
151 | 151 | |
152 | - return [ |
|
153 | - $this->name, |
|
154 | - $this->line, |
|
155 | - $arguments, |
|
156 | - $this->comments, |
|
157 | - ]; |
|
158 | - } |
|
152 | + return [ |
|
153 | + $this->name, |
|
154 | + $this->line, |
|
155 | + $arguments, |
|
156 | + $this->comments, |
|
157 | + ]; |
|
158 | + } |
|
159 | 159 | } |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | * @param string $name The function name. |
56 | 56 | * @param int $line The line where the function starts. |
57 | 57 | */ |
58 | - public function __construct($name, $line) |
|
58 | + public function __construct( $name, $line ) |
|
59 | 59 | { |
60 | 60 | $this->name = $name; |
61 | 61 | $this->line = $line; |
62 | - $this->arguments = []; |
|
62 | + $this->arguments = [ ]; |
|
63 | 63 | $this->argumentIndex = -1; |
64 | 64 | $this->argumentStopped = false; |
65 | 65 | $this->comments = null; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function stopArgument() |
72 | 72 | { |
73 | - if ($this->argumentIndex === -1) { |
|
73 | + if ( $this->argumentIndex === -1 ) { |
|
74 | 74 | $this->argumentIndex = 0; |
75 | 75 | } |
76 | 76 | $this->argumentStopped = true; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function nextArgument() |
83 | 83 | { |
84 | - if ($this->argumentIndex === -1) { |
|
84 | + if ( $this->argumentIndex === -1 ) { |
|
85 | 85 | // This should neve occur, but let's stay safe - During test/development an Exception should be thrown. |
86 | 86 | $this->argumentIndex = 1; |
87 | 87 | } else { |
@@ -95,16 +95,16 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @param string|null $chunk |
97 | 97 | */ |
98 | - public function addArgumentChunk($chunk) |
|
98 | + public function addArgumentChunk( $chunk ) |
|
99 | 99 | { |
100 | - if ($this->argumentStopped === false) { |
|
101 | - if ($this->argumentIndex === -1) { |
|
100 | + if ( $this->argumentStopped === false ) { |
|
101 | + if ( $this->argumentIndex === -1 ) { |
|
102 | 102 | $this->argumentIndex = 0; |
103 | 103 | } |
104 | - if (isset($this->arguments[$this->argumentIndex])) { |
|
105 | - $this->arguments[$this->argumentIndex] .= $chunk; |
|
104 | + if ( isset( $this->arguments[ $this->argumentIndex ] ) ) { |
|
105 | + $this->arguments[ $this->argumentIndex ] .= $chunk; |
|
106 | 106 | } else { |
107 | - $this->arguments[$this->argumentIndex] = $chunk; |
|
107 | + $this->arguments[ $this->argumentIndex ] = $chunk; |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @param ParsedComment $comment |
116 | 116 | */ |
117 | - public function addComment($comment) |
|
117 | + public function addComment( $comment ) |
|
118 | 118 | { |
119 | - if ($this->comments === null) { |
|
120 | - $this->comments = []; |
|
119 | + if ( $this->comments === null ) { |
|
120 | + $this->comments = [ ]; |
|
121 | 121 | } |
122 | - $this->comments[] = $comment; |
|
122 | + $this->comments[ ] = $comment; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function close() |
146 | 146 | { |
147 | - $arguments = []; |
|
148 | - for ($i = 0; $i <= $this->argumentIndex; ++$i) { |
|
149 | - $arguments[$i] = isset($this->arguments[$i]) ? $this->arguments[$i] : null; |
|
147 | + $arguments = [ ]; |
|
148 | + for ( $i = 0; $i <= $this->argumentIndex; ++$i ) { |
|
149 | + $arguments[ $i ] = isset( $this->arguments[ $i ] ) ? $this->arguments[ $i ] : null; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return [ |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | /** |
6 | 6 | * Function parsed by PhpFunctionsScanner. |
7 | 7 | */ |
8 | -class ParsedFunction |
|
9 | -{ |
|
8 | +class ParsedFunction { |
|
10 | 9 | /** |
11 | 10 | * The function name. |
12 | 11 | * |
@@ -55,8 +54,7 @@ discard block |
||
55 | 54 | * @param string $name The function name. |
56 | 55 | * @param int $line The line where the function starts. |
57 | 56 | */ |
58 | - public function __construct($name, $line) |
|
59 | - { |
|
57 | + public function __construct($name, $line) { |
|
60 | 58 | $this->name = $name; |
61 | 59 | $this->line = $line; |
62 | 60 | $this->arguments = []; |
@@ -68,8 +66,7 @@ discard block |
||
68 | 66 | /** |
69 | 67 | * Stop extracting strings from the current argument (because we found something that's not a string). |
70 | 68 | */ |
71 | - public function stopArgument() |
|
72 | - { |
|
69 | + public function stopArgument() { |
|
73 | 70 | if ($this->argumentIndex === -1) { |
74 | 71 | $this->argumentIndex = 0; |
75 | 72 | } |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | /** |
80 | 77 | * Go to the next argument because we a comma was found. |
81 | 78 | */ |
82 | - public function nextArgument() |
|
83 | - { |
|
79 | + public function nextArgument() { |
|
84 | 80 | if ($this->argumentIndex === -1) { |
85 | 81 | // This should neve occur, but let's stay safe - During test/development an Exception should be thrown. |
86 | 82 | $this->argumentIndex = 1; |
@@ -95,8 +91,7 @@ discard block |
||
95 | 91 | * |
96 | 92 | * @param string|null $chunk |
97 | 93 | */ |
98 | - public function addArgumentChunk($chunk) |
|
99 | - { |
|
94 | + public function addArgumentChunk($chunk) { |
|
100 | 95 | if ($this->argumentStopped === false) { |
101 | 96 | if ($this->argumentIndex === -1) { |
102 | 97 | $this->argumentIndex = 0; |
@@ -114,8 +109,7 @@ discard block |
||
114 | 109 | * |
115 | 110 | * @param ParsedComment $comment |
116 | 111 | */ |
117 | - public function addComment($comment) |
|
118 | - { |
|
112 | + public function addComment($comment) { |
|
119 | 113 | if ($this->comments === null) { |
120 | 114 | $this->comments = []; |
121 | 115 | } |
@@ -127,8 +121,7 @@ discard block |
||
127 | 121 | * |
128 | 122 | * @return int Line number. |
129 | 123 | */ |
130 | - public function getLine() |
|
131 | - { |
|
124 | + public function getLine() { |
|
132 | 125 | return $this->line; |
133 | 126 | } |
134 | 127 | |
@@ -142,8 +135,7 @@ discard block |
||
142 | 135 | * |
143 | 136 | * @return array |
144 | 137 | */ |
145 | - public function close() |
|
146 | - { |
|
138 | + public function close() { |
|
147 | 139 | $arguments = []; |
148 | 140 | for ($i = 0; $i <= $this->argumentIndex; ++$i) { |
149 | 141 | $arguments[$i] = isset($this->arguments[$i]) ? $this->arguments[$i] : null; |
@@ -6,189 +6,189 @@ |
||
6 | 6 | |
7 | 7 | class PhpFunctionsScanner extends FunctionsScanner |
8 | 8 | { |
9 | - /** |
|
10 | - * PHP tokens of the code to be parsed. |
|
11 | - * |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected $tokens; |
|
15 | - |
|
16 | - /** |
|
17 | - * If not false, comments will be extracted. |
|
18 | - * |
|
19 | - * @var string|false|array |
|
20 | - */ |
|
21 | - protected $extractComments = false; |
|
22 | - |
|
23 | - /** |
|
24 | - * Enable extracting comments that start with a tag (if $tag is empty all the comments will be extracted). |
|
25 | - * |
|
26 | - * @param mixed $tag |
|
27 | - */ |
|
28 | - public function enableCommentsExtraction($tag = '') |
|
29 | - { |
|
30 | - $this->extractComments = $tag; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Disable comments extraction. |
|
35 | - */ |
|
36 | - public function disableCommentsExtraction() |
|
37 | - { |
|
38 | - $this->extractComments = false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Constructor. |
|
43 | - * |
|
44 | - * @param string $code The php code to scan |
|
45 | - */ |
|
46 | - public function __construct($code) |
|
47 | - { |
|
48 | - $this->tokens = array_values( |
|
49 | - array_filter( |
|
50 | - token_get_all($code), |
|
51 | - function ($token) { |
|
52 | - return !is_array($token) || $token[0] !== T_WHITESPACE; |
|
53 | - } |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - public function getFunctions(array $constants = []) |
|
62 | - { |
|
63 | - $count = count($this->tokens); |
|
64 | - /* @var ParsedFunction[] $bufferFunctions */ |
|
65 | - $bufferFunctions = []; |
|
66 | - /* @var ParsedComment[] $bufferComments */ |
|
67 | - $bufferComments = []; |
|
68 | - /* @var array $functions */ |
|
69 | - $functions = []; |
|
70 | - |
|
71 | - for ($k = 0; $k < $count; ++$k) { |
|
72 | - $value = $this->tokens[$k]; |
|
73 | - |
|
74 | - if (is_string($value)) { |
|
75 | - if (isset($bufferFunctions[0])) { |
|
76 | - switch ($value) { |
|
77 | - case ',': |
|
78 | - $bufferFunctions[0]->nextArgument(); |
|
79 | - break; |
|
80 | - case ')': |
|
81 | - $functions[] = array_shift($bufferFunctions)->close(); |
|
82 | - break; |
|
83 | - case '.': |
|
84 | - break; |
|
85 | - default: |
|
86 | - $bufferFunctions[0]->stopArgument(); |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - continue; |
|
91 | - } |
|
92 | - |
|
93 | - switch ($value[0]) { |
|
94 | - case T_CONSTANT_ENCAPSED_STRING: |
|
95 | - //add an argument to the current function |
|
96 | - if (isset($bufferFunctions[0])) { |
|
97 | - $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1])); |
|
98 | - } |
|
99 | - break; |
|
100 | - |
|
101 | - case T_STRING: |
|
102 | - if (isset($bufferFunctions[0])) { |
|
103 | - if (isset($constants[$value[1]])) { |
|
104 | - $bufferFunctions[0]->addArgumentChunk($constants[$value[1]]); |
|
105 | - break; |
|
106 | - } |
|
107 | - |
|
108 | - if (strtolower($value[1]) === 'null') { |
|
109 | - $bufferFunctions[0]->addArgumentChunk(null); |
|
110 | - break; |
|
111 | - } |
|
112 | - |
|
113 | - $bufferFunctions[0]->stopArgument(); |
|
114 | - } |
|
115 | - |
|
116 | - //new function found |
|
117 | - for ($j = $k + 1; $j < $count; ++$j) { |
|
118 | - $nextToken = $this->tokens[$j]; |
|
119 | - |
|
120 | - if (is_array($nextToken) && $nextToken[0] === T_COMMENT) { |
|
121 | - continue; |
|
122 | - } |
|
123 | - |
|
124 | - if ($nextToken === '(') { |
|
125 | - $newFunction = new ParsedFunction($value[1], $value[2]); |
|
126 | - |
|
127 | - // add comment that was on the line before. |
|
128 | - if (isset($bufferComments[0])) { |
|
129 | - $comment = $bufferComments[0]; |
|
130 | - |
|
131 | - if ($comment->isRelatedWith($newFunction)) { |
|
132 | - $newFunction->addComment($comment); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - array_unshift($bufferFunctions, $newFunction); |
|
137 | - $k = $j; |
|
138 | - } |
|
139 | - break; |
|
140 | - } |
|
141 | - break; |
|
142 | - |
|
143 | - case T_COMMENT: |
|
144 | - $comment = $this->parsePhpComment($value[1], $value[2]); |
|
145 | - |
|
146 | - if ($comment) { |
|
147 | - array_unshift($bufferComments, $comment); |
|
148 | - |
|
149 | - // The comment is inside the function call. |
|
150 | - if (isset($bufferFunctions[0])) { |
|
151 | - $bufferFunctions[0]->addComment($comment); |
|
152 | - } |
|
153 | - } |
|
154 | - break; |
|
155 | - |
|
156 | - default: |
|
157 | - if (isset($bufferFunctions[0])) { |
|
158 | - $bufferFunctions[0]->stopArgument(); |
|
159 | - } |
|
160 | - break; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $functions; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Extract the actual text from a PHP comment. |
|
169 | - * |
|
170 | - * If set, only returns comments that match the prefix(es). |
|
171 | - * |
|
172 | - * @param string $value The PHP comment. |
|
173 | - * @param int $line Line number. |
|
174 | - * |
|
175 | - * @return null|ParsedComment Comment or null if comment extraction is disabled or if there is a prefix mismatch. |
|
176 | - */ |
|
177 | - protected function parsePhpComment($value, $line) |
|
178 | - { |
|
179 | - if ($this->extractComments === false) { |
|
180 | - return null; |
|
181 | - } |
|
182 | - |
|
183 | - //this returns a comment or null |
|
184 | - $comment = ParsedComment::create($value, $line); |
|
185 | - |
|
186 | - $prefixes = array_filter((array) $this->extractComments); |
|
187 | - |
|
188 | - if ($comment && $comment->checkPrefixes($prefixes)) { |
|
189 | - return $comment; |
|
190 | - } |
|
191 | - |
|
192 | - return null; |
|
193 | - } |
|
9 | + /** |
|
10 | + * PHP tokens of the code to be parsed. |
|
11 | + * |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected $tokens; |
|
15 | + |
|
16 | + /** |
|
17 | + * If not false, comments will be extracted. |
|
18 | + * |
|
19 | + * @var string|false|array |
|
20 | + */ |
|
21 | + protected $extractComments = false; |
|
22 | + |
|
23 | + /** |
|
24 | + * Enable extracting comments that start with a tag (if $tag is empty all the comments will be extracted). |
|
25 | + * |
|
26 | + * @param mixed $tag |
|
27 | + */ |
|
28 | + public function enableCommentsExtraction($tag = '') |
|
29 | + { |
|
30 | + $this->extractComments = $tag; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Disable comments extraction. |
|
35 | + */ |
|
36 | + public function disableCommentsExtraction() |
|
37 | + { |
|
38 | + $this->extractComments = false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Constructor. |
|
43 | + * |
|
44 | + * @param string $code The php code to scan |
|
45 | + */ |
|
46 | + public function __construct($code) |
|
47 | + { |
|
48 | + $this->tokens = array_values( |
|
49 | + array_filter( |
|
50 | + token_get_all($code), |
|
51 | + function ($token) { |
|
52 | + return !is_array($token) || $token[0] !== T_WHITESPACE; |
|
53 | + } |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + public function getFunctions(array $constants = []) |
|
62 | + { |
|
63 | + $count = count($this->tokens); |
|
64 | + /* @var ParsedFunction[] $bufferFunctions */ |
|
65 | + $bufferFunctions = []; |
|
66 | + /* @var ParsedComment[] $bufferComments */ |
|
67 | + $bufferComments = []; |
|
68 | + /* @var array $functions */ |
|
69 | + $functions = []; |
|
70 | + |
|
71 | + for ($k = 0; $k < $count; ++$k) { |
|
72 | + $value = $this->tokens[$k]; |
|
73 | + |
|
74 | + if (is_string($value)) { |
|
75 | + if (isset($bufferFunctions[0])) { |
|
76 | + switch ($value) { |
|
77 | + case ',': |
|
78 | + $bufferFunctions[0]->nextArgument(); |
|
79 | + break; |
|
80 | + case ')': |
|
81 | + $functions[] = array_shift($bufferFunctions)->close(); |
|
82 | + break; |
|
83 | + case '.': |
|
84 | + break; |
|
85 | + default: |
|
86 | + $bufferFunctions[0]->stopArgument(); |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + continue; |
|
91 | + } |
|
92 | + |
|
93 | + switch ($value[0]) { |
|
94 | + case T_CONSTANT_ENCAPSED_STRING: |
|
95 | + //add an argument to the current function |
|
96 | + if (isset($bufferFunctions[0])) { |
|
97 | + $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1])); |
|
98 | + } |
|
99 | + break; |
|
100 | + |
|
101 | + case T_STRING: |
|
102 | + if (isset($bufferFunctions[0])) { |
|
103 | + if (isset($constants[$value[1]])) { |
|
104 | + $bufferFunctions[0]->addArgumentChunk($constants[$value[1]]); |
|
105 | + break; |
|
106 | + } |
|
107 | + |
|
108 | + if (strtolower($value[1]) === 'null') { |
|
109 | + $bufferFunctions[0]->addArgumentChunk(null); |
|
110 | + break; |
|
111 | + } |
|
112 | + |
|
113 | + $bufferFunctions[0]->stopArgument(); |
|
114 | + } |
|
115 | + |
|
116 | + //new function found |
|
117 | + for ($j = $k + 1; $j < $count; ++$j) { |
|
118 | + $nextToken = $this->tokens[$j]; |
|
119 | + |
|
120 | + if (is_array($nextToken) && $nextToken[0] === T_COMMENT) { |
|
121 | + continue; |
|
122 | + } |
|
123 | + |
|
124 | + if ($nextToken === '(') { |
|
125 | + $newFunction = new ParsedFunction($value[1], $value[2]); |
|
126 | + |
|
127 | + // add comment that was on the line before. |
|
128 | + if (isset($bufferComments[0])) { |
|
129 | + $comment = $bufferComments[0]; |
|
130 | + |
|
131 | + if ($comment->isRelatedWith($newFunction)) { |
|
132 | + $newFunction->addComment($comment); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + array_unshift($bufferFunctions, $newFunction); |
|
137 | + $k = $j; |
|
138 | + } |
|
139 | + break; |
|
140 | + } |
|
141 | + break; |
|
142 | + |
|
143 | + case T_COMMENT: |
|
144 | + $comment = $this->parsePhpComment($value[1], $value[2]); |
|
145 | + |
|
146 | + if ($comment) { |
|
147 | + array_unshift($bufferComments, $comment); |
|
148 | + |
|
149 | + // The comment is inside the function call. |
|
150 | + if (isset($bufferFunctions[0])) { |
|
151 | + $bufferFunctions[0]->addComment($comment); |
|
152 | + } |
|
153 | + } |
|
154 | + break; |
|
155 | + |
|
156 | + default: |
|
157 | + if (isset($bufferFunctions[0])) { |
|
158 | + $bufferFunctions[0]->stopArgument(); |
|
159 | + } |
|
160 | + break; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $functions; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Extract the actual text from a PHP comment. |
|
169 | + * |
|
170 | + * If set, only returns comments that match the prefix(es). |
|
171 | + * |
|
172 | + * @param string $value The PHP comment. |
|
173 | + * @param int $line Line number. |
|
174 | + * |
|
175 | + * @return null|ParsedComment Comment or null if comment extraction is disabled or if there is a prefix mismatch. |
|
176 | + */ |
|
177 | + protected function parsePhpComment($value, $line) |
|
178 | + { |
|
179 | + if ($this->extractComments === false) { |
|
180 | + return null; |
|
181 | + } |
|
182 | + |
|
183 | + //this returns a comment or null |
|
184 | + $comment = ParsedComment::create($value, $line); |
|
185 | + |
|
186 | + $prefixes = array_filter((array) $this->extractComments); |
|
187 | + |
|
188 | + if ($comment && $comment->checkPrefixes($prefixes)) { |
|
189 | + return $comment; |
|
190 | + } |
|
191 | + |
|
192 | + return null; |
|
193 | + } |
|
194 | 194 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param mixed $tag |
27 | 27 | */ |
28 | - public function enableCommentsExtraction($tag = '') |
|
28 | + public function enableCommentsExtraction( $tag = '' ) |
|
29 | 29 | { |
30 | 30 | $this->extractComments = $tag; |
31 | 31 | } |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param string $code The php code to scan |
45 | 45 | */ |
46 | - public function __construct($code) |
|
46 | + public function __construct( $code ) |
|
47 | 47 | { |
48 | 48 | $this->tokens = array_values( |
49 | 49 | array_filter( |
50 | - token_get_all($code), |
|
51 | - function ($token) { |
|
52 | - return !is_array($token) || $token[0] !== T_WHITESPACE; |
|
50 | + token_get_all( $code ), |
|
51 | + function( $token ) { |
|
52 | + return ! is_array( $token ) || $token[ 0 ] !== T_WHITESPACE; |
|
53 | 53 | } |
54 | 54 | ) |
55 | 55 | ); |
@@ -58,82 +58,82 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * {@inheritdoc} |
60 | 60 | */ |
61 | - public function getFunctions(array $constants = []) |
|
61 | + public function getFunctions( array $constants = [ ] ) |
|
62 | 62 | { |
63 | - $count = count($this->tokens); |
|
63 | + $count = count( $this->tokens ); |
|
64 | 64 | /* @var ParsedFunction[] $bufferFunctions */ |
65 | - $bufferFunctions = []; |
|
65 | + $bufferFunctions = [ ]; |
|
66 | 66 | /* @var ParsedComment[] $bufferComments */ |
67 | - $bufferComments = []; |
|
67 | + $bufferComments = [ ]; |
|
68 | 68 | /* @var array $functions */ |
69 | - $functions = []; |
|
69 | + $functions = [ ]; |
|
70 | 70 | |
71 | - for ($k = 0; $k < $count; ++$k) { |
|
72 | - $value = $this->tokens[$k]; |
|
71 | + for ( $k = 0; $k < $count; ++$k ) { |
|
72 | + $value = $this->tokens[ $k ]; |
|
73 | 73 | |
74 | - if (is_string($value)) { |
|
75 | - if (isset($bufferFunctions[0])) { |
|
76 | - switch ($value) { |
|
74 | + if ( is_string( $value ) ) { |
|
75 | + if ( isset( $bufferFunctions[ 0 ] ) ) { |
|
76 | + switch ( $value ) { |
|
77 | 77 | case ',': |
78 | - $bufferFunctions[0]->nextArgument(); |
|
78 | + $bufferFunctions[ 0 ]->nextArgument(); |
|
79 | 79 | break; |
80 | 80 | case ')': |
81 | - $functions[] = array_shift($bufferFunctions)->close(); |
|
81 | + $functions[ ] = array_shift( $bufferFunctions )->close(); |
|
82 | 82 | break; |
83 | 83 | case '.': |
84 | 84 | break; |
85 | 85 | default: |
86 | - $bufferFunctions[0]->stopArgument(); |
|
86 | + $bufferFunctions[ 0 ]->stopArgument(); |
|
87 | 87 | break; |
88 | 88 | } |
89 | 89 | } |
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | |
93 | - switch ($value[0]) { |
|
93 | + switch ( $value[ 0 ] ) { |
|
94 | 94 | case T_CONSTANT_ENCAPSED_STRING: |
95 | 95 | //add an argument to the current function |
96 | - if (isset($bufferFunctions[0])) { |
|
97 | - $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1])); |
|
96 | + if ( isset( $bufferFunctions[ 0 ] ) ) { |
|
97 | + $bufferFunctions[ 0 ]->addArgumentChunk( PhpCode::convertString( $value[ 1 ] ) ); |
|
98 | 98 | } |
99 | 99 | break; |
100 | 100 | |
101 | 101 | case T_STRING: |
102 | - if (isset($bufferFunctions[0])) { |
|
103 | - if (isset($constants[$value[1]])) { |
|
104 | - $bufferFunctions[0]->addArgumentChunk($constants[$value[1]]); |
|
102 | + if ( isset( $bufferFunctions[ 0 ] ) ) { |
|
103 | + if ( isset( $constants[ $value[ 1 ] ] ) ) { |
|
104 | + $bufferFunctions[ 0 ]->addArgumentChunk( $constants[ $value[ 1 ] ] ); |
|
105 | 105 | break; |
106 | 106 | } |
107 | 107 | |
108 | - if (strtolower($value[1]) === 'null') { |
|
109 | - $bufferFunctions[0]->addArgumentChunk(null); |
|
108 | + if ( strtolower( $value[ 1 ] ) === 'null' ) { |
|
109 | + $bufferFunctions[ 0 ]->addArgumentChunk( null ); |
|
110 | 110 | break; |
111 | 111 | } |
112 | 112 | |
113 | - $bufferFunctions[0]->stopArgument(); |
|
113 | + $bufferFunctions[ 0 ]->stopArgument(); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | //new function found |
117 | - for ($j = $k + 1; $j < $count; ++$j) { |
|
118 | - $nextToken = $this->tokens[$j]; |
|
117 | + for ( $j = $k + 1; $j < $count; ++$j ) { |
|
118 | + $nextToken = $this->tokens[ $j ]; |
|
119 | 119 | |
120 | - if (is_array($nextToken) && $nextToken[0] === T_COMMENT) { |
|
120 | + if ( is_array( $nextToken ) && $nextToken[ 0 ] === T_COMMENT ) { |
|
121 | 121 | continue; |
122 | 122 | } |
123 | 123 | |
124 | - if ($nextToken === '(') { |
|
125 | - $newFunction = new ParsedFunction($value[1], $value[2]); |
|
124 | + if ( $nextToken === '(' ) { |
|
125 | + $newFunction = new ParsedFunction( $value[ 1 ], $value[ 2 ] ); |
|
126 | 126 | |
127 | 127 | // add comment that was on the line before. |
128 | - if (isset($bufferComments[0])) { |
|
129 | - $comment = $bufferComments[0]; |
|
128 | + if ( isset( $bufferComments[ 0 ] ) ) { |
|
129 | + $comment = $bufferComments[ 0 ]; |
|
130 | 130 | |
131 | - if ($comment->isRelatedWith($newFunction)) { |
|
132 | - $newFunction->addComment($comment); |
|
131 | + if ( $comment->isRelatedWith( $newFunction ) ) { |
|
132 | + $newFunction->addComment( $comment ); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | - array_unshift($bufferFunctions, $newFunction); |
|
136 | + array_unshift( $bufferFunctions, $newFunction ); |
|
137 | 137 | $k = $j; |
138 | 138 | } |
139 | 139 | break; |
@@ -141,21 +141,21 @@ discard block |
||
141 | 141 | break; |
142 | 142 | |
143 | 143 | case T_COMMENT: |
144 | - $comment = $this->parsePhpComment($value[1], $value[2]); |
|
144 | + $comment = $this->parsePhpComment( $value[ 1 ], $value[ 2 ] ); |
|
145 | 145 | |
146 | - if ($comment) { |
|
147 | - array_unshift($bufferComments, $comment); |
|
146 | + if ( $comment ) { |
|
147 | + array_unshift( $bufferComments, $comment ); |
|
148 | 148 | |
149 | 149 | // The comment is inside the function call. |
150 | - if (isset($bufferFunctions[0])) { |
|
151 | - $bufferFunctions[0]->addComment($comment); |
|
150 | + if ( isset( $bufferFunctions[ 0 ] ) ) { |
|
151 | + $bufferFunctions[ 0 ]->addComment( $comment ); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | break; |
155 | 155 | |
156 | 156 | default: |
157 | - if (isset($bufferFunctions[0])) { |
|
158 | - $bufferFunctions[0]->stopArgument(); |
|
157 | + if ( isset( $bufferFunctions[ 0 ] ) ) { |
|
158 | + $bufferFunctions[ 0 ]->stopArgument(); |
|
159 | 159 | } |
160 | 160 | break; |
161 | 161 | } |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @return null|ParsedComment Comment or null if comment extraction is disabled or if there is a prefix mismatch. |
176 | 176 | */ |
177 | - protected function parsePhpComment($value, $line) |
|
177 | + protected function parsePhpComment( $value, $line ) |
|
178 | 178 | { |
179 | - if ($this->extractComments === false) { |
|
179 | + if ( $this->extractComments === false ) { |
|
180 | 180 | return null; |
181 | 181 | } |
182 | 182 | |
183 | 183 | //this returns a comment or null |
184 | - $comment = ParsedComment::create($value, $line); |
|
184 | + $comment = ParsedComment::create( $value, $line ); |
|
185 | 185 | |
186 | - $prefixes = array_filter((array) $this->extractComments); |
|
186 | + $prefixes = array_filter( (array)$this->extractComments ); |
|
187 | 187 | |
188 | - if ($comment && $comment->checkPrefixes($prefixes)) { |
|
188 | + if ( $comment && $comment->checkPrefixes( $prefixes ) ) { |
|
189 | 189 | return $comment; |
190 | 190 | } |
191 | 191 |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use Gettext\Extractors\PhpCode; |
6 | 6 | |
7 | -class PhpFunctionsScanner extends FunctionsScanner |
|
8 | -{ |
|
7 | +class PhpFunctionsScanner extends FunctionsScanner { |
|
9 | 8 | /** |
10 | 9 | * PHP tokens of the code to be parsed. |
11 | 10 | * |
@@ -25,16 +24,14 @@ discard block |
||
25 | 24 | * |
26 | 25 | * @param mixed $tag |
27 | 26 | */ |
28 | - public function enableCommentsExtraction($tag = '') |
|
29 | - { |
|
27 | + public function enableCommentsExtraction($tag = '') { |
|
30 | 28 | $this->extractComments = $tag; |
31 | 29 | } |
32 | 30 | |
33 | 31 | /** |
34 | 32 | * Disable comments extraction. |
35 | 33 | */ |
36 | - public function disableCommentsExtraction() |
|
37 | - { |
|
34 | + public function disableCommentsExtraction() { |
|
38 | 35 | $this->extractComments = false; |
39 | 36 | } |
40 | 37 | |
@@ -43,8 +40,7 @@ discard block |
||
43 | 40 | * |
44 | 41 | * @param string $code The php code to scan |
45 | 42 | */ |
46 | - public function __construct($code) |
|
47 | - { |
|
43 | + public function __construct($code) { |
|
48 | 44 | $this->tokens = array_values( |
49 | 45 | array_filter( |
50 | 46 | token_get_all($code), |
@@ -58,8 +54,7 @@ discard block |
||
58 | 54 | /** |
59 | 55 | * {@inheritdoc} |
60 | 56 | */ |
61 | - public function getFunctions(array $constants = []) |
|
62 | - { |
|
57 | + public function getFunctions(array $constants = []) { |
|
63 | 58 | $count = count($this->tokens); |
64 | 59 | /* @var ParsedFunction[] $bufferFunctions */ |
65 | 60 | $bufferFunctions = []; |
@@ -174,8 +169,7 @@ discard block |
||
174 | 169 | * |
175 | 170 | * @return null|ParsedComment Comment or null if comment extraction is disabled or if there is a prefix mismatch. |
176 | 171 | */ |
177 | - protected function parsePhpComment($value, $line) |
|
178 | - { |
|
172 | + protected function parsePhpComment($value, $line) { |
|
179 | 173 | if ($this->extractComments === false) { |
180 | 174 | return null; |
181 | 175 | } |