@@ -6,140 +6,140 @@ |
||
6 | 6 | |
7 | 7 | class Po extends Generator implements GeneratorInterface |
8 | 8 | { |
9 | - public static $options = [ |
|
10 | - 'noLocation' => false, |
|
11 | - ]; |
|
12 | - |
|
13 | - /** |
|
14 | - * {@parentDoc}. |
|
15 | - */ |
|
16 | - public static function toString(Translations $translations, array $options = []) |
|
17 | - { |
|
18 | - $options += static::$options; |
|
19 | - |
|
20 | - $pluralForm = $translations->getPluralForms(); |
|
21 | - $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
|
22 | - $lines = ['msgid ""', 'msgstr ""']; |
|
23 | - |
|
24 | - foreach ($translations->getHeaders() as $name => $value) { |
|
25 | - $lines[] = sprintf('"%s: %s\\n"', $name, $value); |
|
26 | - } |
|
27 | - |
|
28 | - $lines[] = ''; |
|
29 | - |
|
30 | - //Translations |
|
31 | - foreach ($translations as $translation) { |
|
32 | - if ($translation->hasComments()) { |
|
33 | - foreach ($translation->getComments() as $comment) { |
|
34 | - $lines[] = '# '.$comment; |
|
35 | - } |
|
36 | - } |
|
37 | - |
|
38 | - if ($translation->hasExtractedComments()) { |
|
39 | - foreach ($translation->getExtractedComments() as $comment) { |
|
40 | - $lines[] = '#. '.$comment; |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - if (!$options['noLocation'] && $translation->hasReferences()) { |
|
45 | - foreach ($translation->getReferences() as $reference) { |
|
46 | - $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - if ($translation->hasFlags()) { |
|
51 | - $lines[] = '#, '.implode(',', $translation->getFlags()); |
|
52 | - } |
|
53 | - |
|
54 | - $prefix = $translation->isDisabled() ? '#~ ' : ''; |
|
55 | - |
|
56 | - if ($translation->hasContext()) { |
|
57 | - $lines[] = $prefix.'msgctxt '.static::convertString($translation->getContext()); |
|
58 | - } |
|
59 | - |
|
60 | - static::addLines($lines, $prefix.'msgid', $translation->getOriginal()); |
|
61 | - |
|
62 | - if ($translation->hasPlural()) { |
|
63 | - static::addLines($lines, $prefix.'msgid_plural', $translation->getPlural()); |
|
64 | - static::addLines($lines, $prefix.'msgstr[0]', $translation->getTranslation()); |
|
65 | - |
|
66 | - foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) { |
|
67 | - static::addLines($lines, $prefix.'msgstr['.($k + 1).']', $v); |
|
68 | - } |
|
69 | - } else { |
|
70 | - static::addLines($lines, $prefix.'msgstr', $translation->getTranslation()); |
|
71 | - } |
|
72 | - |
|
73 | - $lines[] = ''; |
|
74 | - } |
|
75 | - |
|
76 | - return implode("\n", $lines); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Escapes and adds double quotes to a string. |
|
81 | - * |
|
82 | - * @param string $string |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - protected static function multilineQuote($string) |
|
87 | - { |
|
88 | - $lines = explode("\n", $string); |
|
89 | - $last = count($lines) - 1; |
|
90 | - |
|
91 | - foreach ($lines as $k => $line) { |
|
92 | - if ($k === $last) { |
|
93 | - $lines[$k] = static::convertString($line); |
|
94 | - } else { |
|
95 | - $lines[$k] = static::convertString($line."\n"); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - return $lines; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Add one or more lines depending whether the string is multiline or not. |
|
104 | - * |
|
105 | - * @param array &$lines |
|
106 | - * @param string $name |
|
107 | - * @param string $value |
|
108 | - */ |
|
109 | - protected static function addLines(array &$lines, $name, $value) |
|
110 | - { |
|
111 | - $newLines = static::multilineQuote($value); |
|
112 | - |
|
113 | - if (count($newLines) === 1) { |
|
114 | - $lines[] = $name.' '.$newLines[0]; |
|
115 | - } else { |
|
116 | - $lines[] = $name.' ""'; |
|
117 | - |
|
118 | - foreach ($newLines as $line) { |
|
119 | - $lines[] = $line; |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Convert a string to its PO representation. |
|
126 | - * |
|
127 | - * @param string $value |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public static function convertString($value) |
|
132 | - { |
|
133 | - return '"'.strtr( |
|
134 | - $value, |
|
135 | - [ |
|
136 | - "\x00" => '', |
|
137 | - '\\' => '\\\\', |
|
138 | - "\t" => '\t', |
|
139 | - "\r" => '\r', |
|
140 | - "\n" => '\n', |
|
141 | - '"' => '\\"', |
|
142 | - ] |
|
143 | - ).'"'; |
|
144 | - } |
|
9 | + public static $options = [ |
|
10 | + 'noLocation' => false, |
|
11 | + ]; |
|
12 | + |
|
13 | + /** |
|
14 | + * {@parentDoc}. |
|
15 | + */ |
|
16 | + public static function toString(Translations $translations, array $options = []) |
|
17 | + { |
|
18 | + $options += static::$options; |
|
19 | + |
|
20 | + $pluralForm = $translations->getPluralForms(); |
|
21 | + $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
|
22 | + $lines = ['msgid ""', 'msgstr ""']; |
|
23 | + |
|
24 | + foreach ($translations->getHeaders() as $name => $value) { |
|
25 | + $lines[] = sprintf('"%s: %s\\n"', $name, $value); |
|
26 | + } |
|
27 | + |
|
28 | + $lines[] = ''; |
|
29 | + |
|
30 | + //Translations |
|
31 | + foreach ($translations as $translation) { |
|
32 | + if ($translation->hasComments()) { |
|
33 | + foreach ($translation->getComments() as $comment) { |
|
34 | + $lines[] = '# '.$comment; |
|
35 | + } |
|
36 | + } |
|
37 | + |
|
38 | + if ($translation->hasExtractedComments()) { |
|
39 | + foreach ($translation->getExtractedComments() as $comment) { |
|
40 | + $lines[] = '#. '.$comment; |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + if (!$options['noLocation'] && $translation->hasReferences()) { |
|
45 | + foreach ($translation->getReferences() as $reference) { |
|
46 | + $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + if ($translation->hasFlags()) { |
|
51 | + $lines[] = '#, '.implode(',', $translation->getFlags()); |
|
52 | + } |
|
53 | + |
|
54 | + $prefix = $translation->isDisabled() ? '#~ ' : ''; |
|
55 | + |
|
56 | + if ($translation->hasContext()) { |
|
57 | + $lines[] = $prefix.'msgctxt '.static::convertString($translation->getContext()); |
|
58 | + } |
|
59 | + |
|
60 | + static::addLines($lines, $prefix.'msgid', $translation->getOriginal()); |
|
61 | + |
|
62 | + if ($translation->hasPlural()) { |
|
63 | + static::addLines($lines, $prefix.'msgid_plural', $translation->getPlural()); |
|
64 | + static::addLines($lines, $prefix.'msgstr[0]', $translation->getTranslation()); |
|
65 | + |
|
66 | + foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) { |
|
67 | + static::addLines($lines, $prefix.'msgstr['.($k + 1).']', $v); |
|
68 | + } |
|
69 | + } else { |
|
70 | + static::addLines($lines, $prefix.'msgstr', $translation->getTranslation()); |
|
71 | + } |
|
72 | + |
|
73 | + $lines[] = ''; |
|
74 | + } |
|
75 | + |
|
76 | + return implode("\n", $lines); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Escapes and adds double quotes to a string. |
|
81 | + * |
|
82 | + * @param string $string |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + protected static function multilineQuote($string) |
|
87 | + { |
|
88 | + $lines = explode("\n", $string); |
|
89 | + $last = count($lines) - 1; |
|
90 | + |
|
91 | + foreach ($lines as $k => $line) { |
|
92 | + if ($k === $last) { |
|
93 | + $lines[$k] = static::convertString($line); |
|
94 | + } else { |
|
95 | + $lines[$k] = static::convertString($line."\n"); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + return $lines; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Add one or more lines depending whether the string is multiline or not. |
|
104 | + * |
|
105 | + * @param array &$lines |
|
106 | + * @param string $name |
|
107 | + * @param string $value |
|
108 | + */ |
|
109 | + protected static function addLines(array &$lines, $name, $value) |
|
110 | + { |
|
111 | + $newLines = static::multilineQuote($value); |
|
112 | + |
|
113 | + if (count($newLines) === 1) { |
|
114 | + $lines[] = $name.' '.$newLines[0]; |
|
115 | + } else { |
|
116 | + $lines[] = $name.' ""'; |
|
117 | + |
|
118 | + foreach ($newLines as $line) { |
|
119 | + $lines[] = $line; |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Convert a string to its PO representation. |
|
126 | + * |
|
127 | + * @param string $value |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public static function convertString($value) |
|
132 | + { |
|
133 | + return '"'.strtr( |
|
134 | + $value, |
|
135 | + [ |
|
136 | + "\x00" => '', |
|
137 | + '\\' => '\\\\', |
|
138 | + "\t" => '\t', |
|
139 | + "\r" => '\r', |
|
140 | + "\n" => '\n', |
|
141 | + '"' => '\\"', |
|
142 | + ] |
|
143 | + ).'"'; |
|
144 | + } |
|
145 | 145 | } |
@@ -13,67 +13,67 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@parentDoc}. |
15 | 15 | */ |
16 | - public static function toString(Translations $translations, array $options = []) |
|
16 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
17 | 17 | { |
18 | 18 | $options += static::$options; |
19 | 19 | |
20 | 20 | $pluralForm = $translations->getPluralForms(); |
21 | - $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
|
22 | - $lines = ['msgid ""', 'msgstr ""']; |
|
21 | + $pluralSize = is_array( $pluralForm ) ? ( $pluralForm[ 0 ] - 1 ) : null; |
|
22 | + $lines = [ 'msgid ""', 'msgstr ""' ]; |
|
23 | 23 | |
24 | - foreach ($translations->getHeaders() as $name => $value) { |
|
25 | - $lines[] = sprintf('"%s: %s\\n"', $name, $value); |
|
24 | + foreach ( $translations->getHeaders() as $name => $value ) { |
|
25 | + $lines[ ] = sprintf( '"%s: %s\\n"', $name, $value ); |
|
26 | 26 | } |
27 | 27 | |
28 | - $lines[] = ''; |
|
28 | + $lines[ ] = ''; |
|
29 | 29 | |
30 | 30 | //Translations |
31 | - foreach ($translations as $translation) { |
|
32 | - if ($translation->hasComments()) { |
|
33 | - foreach ($translation->getComments() as $comment) { |
|
34 | - $lines[] = '# '.$comment; |
|
31 | + foreach ( $translations as $translation ) { |
|
32 | + if ( $translation->hasComments() ) { |
|
33 | + foreach ( $translation->getComments() as $comment ) { |
|
34 | + $lines[ ] = '# ' . $comment; |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | - if ($translation->hasExtractedComments()) { |
|
39 | - foreach ($translation->getExtractedComments() as $comment) { |
|
40 | - $lines[] = '#. '.$comment; |
|
38 | + if ( $translation->hasExtractedComments() ) { |
|
39 | + foreach ( $translation->getExtractedComments() as $comment ) { |
|
40 | + $lines[ ] = '#. ' . $comment; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - if (!$options['noLocation'] && $translation->hasReferences()) { |
|
45 | - foreach ($translation->getReferences() as $reference) { |
|
46 | - $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); |
|
44 | + if ( ! $options[ 'noLocation' ] && $translation->hasReferences() ) { |
|
45 | + foreach ( $translation->getReferences() as $reference ) { |
|
46 | + $lines[ ] = '#: ' . $reference[ 0 ] . ( ! is_null( $reference[ 1 ] ) ? ':' . $reference[ 1 ] : null ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - if ($translation->hasFlags()) { |
|
51 | - $lines[] = '#, '.implode(',', $translation->getFlags()); |
|
50 | + if ( $translation->hasFlags() ) { |
|
51 | + $lines[ ] = '#, ' . implode( ',', $translation->getFlags() ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $prefix = $translation->isDisabled() ? '#~ ' : ''; |
55 | 55 | |
56 | - if ($translation->hasContext()) { |
|
57 | - $lines[] = $prefix.'msgctxt '.static::convertString($translation->getContext()); |
|
56 | + if ( $translation->hasContext() ) { |
|
57 | + $lines[ ] = $prefix . 'msgctxt ' . static::convertString( $translation->getContext() ); |
|
58 | 58 | } |
59 | 59 | |
60 | - static::addLines($lines, $prefix.'msgid', $translation->getOriginal()); |
|
60 | + static::addLines( $lines, $prefix . 'msgid', $translation->getOriginal() ); |
|
61 | 61 | |
62 | - if ($translation->hasPlural()) { |
|
63 | - static::addLines($lines, $prefix.'msgid_plural', $translation->getPlural()); |
|
64 | - static::addLines($lines, $prefix.'msgstr[0]', $translation->getTranslation()); |
|
62 | + if ( $translation->hasPlural() ) { |
|
63 | + static::addLines( $lines, $prefix . 'msgid_plural', $translation->getPlural() ); |
|
64 | + static::addLines( $lines, $prefix . 'msgstr[0]', $translation->getTranslation() ); |
|
65 | 65 | |
66 | - foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) { |
|
67 | - static::addLines($lines, $prefix.'msgstr['.($k + 1).']', $v); |
|
66 | + foreach ( $translation->getPluralTranslations( $pluralSize ) as $k => $v ) { |
|
67 | + static::addLines( $lines, $prefix . 'msgstr[' . ( $k + 1 ) . ']', $v ); |
|
68 | 68 | } |
69 | 69 | } else { |
70 | - static::addLines($lines, $prefix.'msgstr', $translation->getTranslation()); |
|
70 | + static::addLines( $lines, $prefix . 'msgstr', $translation->getTranslation() ); |
|
71 | 71 | } |
72 | 72 | |
73 | - $lines[] = ''; |
|
73 | + $lines[ ] = ''; |
|
74 | 74 | } |
75 | 75 | |
76 | - return implode("\n", $lines); |
|
76 | + return implode( "\n", $lines ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - protected static function multilineQuote($string) |
|
86 | + protected static function multilineQuote( $string ) |
|
87 | 87 | { |
88 | - $lines = explode("\n", $string); |
|
89 | - $last = count($lines) - 1; |
|
88 | + $lines = explode( "\n", $string ); |
|
89 | + $last = count( $lines ) - 1; |
|
90 | 90 | |
91 | - foreach ($lines as $k => $line) { |
|
92 | - if ($k === $last) { |
|
93 | - $lines[$k] = static::convertString($line); |
|
91 | + foreach ( $lines as $k => $line ) { |
|
92 | + if ( $k === $last ) { |
|
93 | + $lines[ $k ] = static::convertString( $line ); |
|
94 | 94 | } else { |
95 | - $lines[$k] = static::convertString($line."\n"); |
|
95 | + $lines[ $k ] = static::convertString( $line . "\n" ); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -106,17 +106,17 @@ discard block |
||
106 | 106 | * @param string $name |
107 | 107 | * @param string $value |
108 | 108 | */ |
109 | - protected static function addLines(array &$lines, $name, $value) |
|
109 | + protected static function addLines( array &$lines, $name, $value ) |
|
110 | 110 | { |
111 | - $newLines = static::multilineQuote($value); |
|
111 | + $newLines = static::multilineQuote( $value ); |
|
112 | 112 | |
113 | - if (count($newLines) === 1) { |
|
114 | - $lines[] = $name.' '.$newLines[0]; |
|
113 | + if ( count( $newLines ) === 1 ) { |
|
114 | + $lines[ ] = $name . ' ' . $newLines[ 0 ]; |
|
115 | 115 | } else { |
116 | - $lines[] = $name.' ""'; |
|
116 | + $lines[ ] = $name . ' ""'; |
|
117 | 117 | |
118 | - foreach ($newLines as $line) { |
|
119 | - $lines[] = $line; |
|
118 | + foreach ( $newLines as $line ) { |
|
119 | + $lines[ ] = $line; |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public static function convertString($value) |
|
131 | + public static function convertString( $value ) |
|
132 | 132 | { |
133 | - return '"'.strtr( |
|
133 | + return '"' . strtr( |
|
134 | 134 | $value, |
135 | 135 | [ |
136 | 136 | "\x00" => '', |
@@ -140,6 +140,6 @@ discard block |
||
140 | 140 | "\n" => '\n', |
141 | 141 | '"' => '\\"', |
142 | 142 | ] |
143 | - ).'"'; |
|
143 | + ) . '"'; |
|
144 | 144 | } |
145 | 145 | } |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use Gettext\Translations; |
6 | 6 | |
7 | -class Po extends Generator implements GeneratorInterface |
|
8 | -{ |
|
7 | +class Po extends Generator implements GeneratorInterface { |
|
9 | 8 | public static $options = [ |
10 | 9 | 'noLocation' => false, |
11 | 10 | ]; |
@@ -13,8 +12,7 @@ discard block |
||
13 | 12 | /** |
14 | 13 | * {@parentDoc}. |
15 | 14 | */ |
16 | - public static function toString(Translations $translations, array $options = []) |
|
17 | - { |
|
15 | + public static function toString(Translations $translations, array $options = []) { |
|
18 | 16 | $options += static::$options; |
19 | 17 | |
20 | 18 | $pluralForm = $translations->getPluralForms(); |
@@ -83,8 +81,7 @@ discard block |
||
83 | 81 | * |
84 | 82 | * @return string |
85 | 83 | */ |
86 | - protected static function multilineQuote($string) |
|
87 | - { |
|
84 | + protected static function multilineQuote($string) { |
|
88 | 85 | $lines = explode("\n", $string); |
89 | 86 | $last = count($lines) - 1; |
90 | 87 | |
@@ -106,8 +103,7 @@ discard block |
||
106 | 103 | * @param string $name |
107 | 104 | * @param string $value |
108 | 105 | */ |
109 | - protected static function addLines(array &$lines, $name, $value) |
|
110 | - { |
|
106 | + protected static function addLines(array &$lines, $name, $value) { |
|
111 | 107 | $newLines = static::multilineQuote($value); |
112 | 108 | |
113 | 109 | if (count($newLines) === 1) { |
@@ -128,8 +124,7 @@ discard block |
||
128 | 124 | * |
129 | 125 | * @return string |
130 | 126 | */ |
131 | - public static function convertString($value) |
|
132 | - { |
|
127 | + public static function convertString($value) { |
|
133 | 128 | return '"'.strtr( |
134 | 129 | $value, |
135 | 130 | [ |
@@ -7,20 +7,20 @@ |
||
7 | 7 | |
8 | 8 | class Json extends Generator implements GeneratorInterface |
9 | 9 | { |
10 | - use MultidimensionalArrayTrait; |
|
10 | + use MultidimensionalArrayTrait; |
|
11 | 11 | |
12 | - public static $options = [ |
|
13 | - 'json' => 0, |
|
14 | - 'includeHeaders' => false, |
|
15 | - ]; |
|
12 | + public static $options = [ |
|
13 | + 'json' => 0, |
|
14 | + 'includeHeaders' => false, |
|
15 | + ]; |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - public static function toString(Translations $translations, array $options = []) |
|
21 | - { |
|
22 | - $options += static::$options; |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + public static function toString(Translations $translations, array $options = []) |
|
21 | + { |
|
22 | + $options += static::$options; |
|
23 | 23 | |
24 | - return json_encode(static::toArray($translations, $options['includeHeaders'], true), $options['json']); |
|
25 | - } |
|
24 | + return json_encode(static::toArray($translations, $options['includeHeaders'], true), $options['json']); |
|
25 | + } |
|
26 | 26 | } |
@@ -17,10 +17,10 @@ |
||
17 | 17 | /** |
18 | 18 | * {@inheritdoc} |
19 | 19 | */ |
20 | - public static function toString(Translations $translations, array $options = []) |
|
20 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
21 | 21 | { |
22 | 22 | $options += static::$options; |
23 | 23 | |
24 | - return json_encode(static::toArray($translations, $options['includeHeaders'], true), $options['json']); |
|
24 | + return json_encode( static::toArray( $translations, $options[ 'includeHeaders' ], true ), $options[ 'json' ] ); |
|
25 | 25 | } |
26 | 26 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | use Gettext\Translations; |
6 | 6 | use Gettext\Utils\MultidimensionalArrayTrait; |
7 | 7 | |
8 | -class Json extends Generator implements GeneratorInterface |
|
9 | -{ |
|
8 | +class Json extends Generator implements GeneratorInterface { |
|
10 | 9 | use MultidimensionalArrayTrait; |
11 | 10 | |
12 | 11 | public static $options = [ |
@@ -17,8 +16,7 @@ discard block |
||
17 | 16 | /** |
18 | 17 | * {@inheritdoc} |
19 | 18 | */ |
20 | - public static function toString(Translations $translations, array $options = []) |
|
21 | - { |
|
19 | + public static function toString(Translations $translations, array $options = []) { |
|
22 | 20 | $options += static::$options; |
23 | 21 | |
24 | 22 | return json_encode(static::toArray($translations, $options['includeHeaders'], true), $options['json']); |
@@ -6,17 +6,17 @@ |
||
6 | 6 | |
7 | 7 | abstract class Generator implements GeneratorInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * {@inheritdoc} |
|
11 | - */ |
|
12 | - public static function toFile(Translations $translations, $file, array $options = []) |
|
13 | - { |
|
14 | - $content = static::toString($translations, $options); |
|
9 | + /** |
|
10 | + * {@inheritdoc} |
|
11 | + */ |
|
12 | + public static function toFile(Translations $translations, $file, array $options = []) |
|
13 | + { |
|
14 | + $content = static::toString($translations, $options); |
|
15 | 15 | |
16 | - if (file_put_contents($file, $content) === false) { |
|
17 | - return false; |
|
18 | - } |
|
16 | + if (file_put_contents($file, $content) === false) { |
|
17 | + return false; |
|
18 | + } |
|
19 | 19 | |
20 | - return true; |
|
21 | - } |
|
20 | + return true; |
|
21 | + } |
|
22 | 22 | } |
@@ -9,11 +9,11 @@ |
||
9 | 9 | /** |
10 | 10 | * {@inheritdoc} |
11 | 11 | */ |
12 | - public static function toFile(Translations $translations, $file, array $options = []) |
|
12 | + public static function toFile( Translations $translations, $file, array $options = [ ] ) |
|
13 | 13 | { |
14 | - $content = static::toString($translations, $options); |
|
14 | + $content = static::toString( $translations, $options ); |
|
15 | 15 | |
16 | - if (file_put_contents($file, $content) === false) { |
|
16 | + if ( file_put_contents( $file, $content ) === false ) { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 |
@@ -4,13 +4,11 @@ |
||
4 | 4 | |
5 | 5 | use Gettext\Translations; |
6 | 6 | |
7 | -abstract class Generator implements GeneratorInterface |
|
8 | -{ |
|
7 | +abstract class Generator implements GeneratorInterface { |
|
9 | 8 | /** |
10 | 9 | * {@inheritdoc} |
11 | 10 | */ |
12 | - public static function toFile(Translations $translations, $file, array $options = []) |
|
13 | - { |
|
11 | + public static function toFile(Translations $translations, $file, array $options = []) { |
|
14 | 12 | $content = static::toString($translations, $options); |
15 | 13 | |
16 | 14 | if (file_put_contents($file, $content) === false) { |
@@ -8,25 +8,25 @@ |
||
8 | 8 | |
9 | 9 | class Yaml extends Generator implements GeneratorInterface |
10 | 10 | { |
11 | - use MultidimensionalArrayTrait; |
|
11 | + use MultidimensionalArrayTrait; |
|
12 | 12 | |
13 | - public static $options = [ |
|
14 | - 'includeHeaders' => false, |
|
15 | - 'indent' => 2, |
|
16 | - 'inline' => 4, |
|
17 | - ]; |
|
13 | + public static $options = [ |
|
14 | + 'includeHeaders' => false, |
|
15 | + 'indent' => 2, |
|
16 | + 'inline' => 4, |
|
17 | + ]; |
|
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - */ |
|
22 | - public static function toString(Translations $translations, array $options = []) |
|
23 | - { |
|
24 | - $options += static::$options; |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + */ |
|
22 | + public static function toString(Translations $translations, array $options = []) |
|
23 | + { |
|
24 | + $options += static::$options; |
|
25 | 25 | |
26 | - return YamlDumper::dump( |
|
27 | - static::toArray($translations, $options['includeHeaders']), |
|
28 | - $options['inline'], |
|
29 | - $options['indent'] |
|
30 | - ); |
|
31 | - } |
|
26 | + return YamlDumper::dump( |
|
27 | + static::toArray($translations, $options['includeHeaders']), |
|
28 | + $options['inline'], |
|
29 | + $options['indent'] |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | use Gettext\Utils\MultidimensionalArrayTrait; |
7 | 7 | use Symfony\Component\Yaml\Yaml as YamlDumper; |
8 | 8 | |
9 | -class Yaml extends Generator implements GeneratorInterface |
|
10 | -{ |
|
9 | +class Yaml extends Generator implements GeneratorInterface { |
|
11 | 10 | use MultidimensionalArrayTrait; |
12 | 11 | |
13 | 12 | public static $options = [ |
@@ -19,8 +18,7 @@ discard block |
||
19 | 18 | /** |
20 | 19 | * {@inheritdoc} |
21 | 20 | */ |
22 | - public static function toString(Translations $translations, array $options = []) |
|
23 | - { |
|
21 | + public static function toString(Translations $translations, array $options = []) { |
|
24 | 22 | $options += static::$options; |
25 | 23 | |
26 | 24 | return YamlDumper::dump( |
@@ -19,14 +19,14 @@ |
||
19 | 19 | /** |
20 | 20 | * {@inheritdoc} |
21 | 21 | */ |
22 | - public static function toString(Translations $translations, array $options = []) |
|
22 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
23 | 23 | { |
24 | 24 | $options += static::$options; |
25 | 25 | |
26 | 26 | return YamlDumper::dump( |
27 | - static::toArray($translations, $options['includeHeaders']), |
|
28 | - $options['inline'], |
|
29 | - $options['indent'] |
|
27 | + static::toArray( $translations, $options[ 'includeHeaders' ] ), |
|
28 | + $options[ 'inline' ], |
|
29 | + $options[ 'indent' ] |
|
30 | 30 | ); |
31 | 31 | } |
32 | 32 | } |
@@ -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 | } |