GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — filters ( 8ea8b6...7e9bcd )
by
unknown
10:01
created

ContentBlockHelper   B

Complexity

Total Complexity 48

Size/Duplication

Total Lines 341
Duplicated Lines 4.69 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 48
lcom 1
cbo 3
dl 16
loc 341
rs 8.4865
c 4
b 1
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A compileContentString() 0 7 1
C processData() 0 54 12
A replaceForms() 0 21 4
C renderUrl() 10 27 8
B sanitizeChunk() 6 24 6
B compileChunk() 0 28 5
A applyFormatter() 0 13 4
A fetchChunkByKey() 0 18 2
A preloadChunks() 0 18 2
A getChunk() 0 19 4

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ContentBlockHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ContentBlockHelper, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace app\modules\core\helpers;
3
4
use app\modules\core\models\ContentBlock;
5
use devgroup\TagDependencyHelper\ActiveRecordHelper;
6
use yii\caching\TagDependency;
7
use yii\helpers\ArrayHelper;
8
use yii\helpers\Url;
9
use yii;
10
use app;
11
12
/**
13
 * Class ContentBlockHelper
14
 * Main public static method compileContentString() uses submethods to extract chunk calls from model content field,
15
 * fetch chunks from data base table, then compile it and replace chunk calls with compiled chunks data
16
 * Example chunk call in model content field should be like: [[$chunk param='value'|'default value' param2=42]].
17
 * Chunk declaration should be like : <p>String: [[+param]]</p> <p>Float: [[+param2:format, param1, param2]]</p>
18
 * All supported formats you can find at Yii::$app->formatter
19
 *
20
 * @package app\modules\core\helpers
21
 */
22
class ContentBlockHelper
23
{
24
    private static $chunksByKey = [];
25
26
    /**
27
     * Compiles content string by injecting chunks into content
28
     * Preloads chunks which have preload = 1
29
     *
30
     * @param  string $content Original content with chunk calls
31
     * @param  string $content_key Key for caching compiled content version
32
     * @param  yii\caching\Dependency $dependency Cache dependency
33
     * @return string Compiled content with injected chunks
34
     */
35
    public static function compileContentString($content, $content_key, $dependency)
36
    {
37
        self::preloadChunks();
38
        $output = self::processData($content, $content_key, $dependency);
39
        $output = self::processData($output, $content_key, $dependency, '', false);
40
        return $output;
41
    }
42
43
    /**
44
     * Finding chunk calls with regexp
45
     * Iterate matches
46
     * While iterating:
47
     * Extracts single chunk data with sanitizeChunk() method
48
     * Fetches chunk by key using fetchChunkByKey(), who returns chunk value by key from static array if exists, otherwise from db
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
49
     * Compiles single chunk using compileChunk() method
50
     * Replaces single chunk call with compiled chunk data in the model content
51
     *
52
     * @param  string $content_key Key for caching compiled content version
53
     * @param  yii\caching\Dependency $dependency Cache dependency
54
     * @param  bool $preprocess flag to separate rendering non cacheable chunks such as Form
55
     * @param  string $content
56
     * @param  string $chunk_key ContentBlock key string to prevent endless recursion
57
     * @return string
58
     */
59
    private static function processData($content, $content_key, $dependency, $chunk_key = '', $preprocess = true)
60
    {
61
        $matches = [];
62
        $replacement = '';
63
        preg_match_all('%\[\[([^\]\[]+)\]\]%ui', $content, $matches);
64
        if (!empty($matches[0])) {
65
            foreach ($matches[0] as $k => $rawChunk) {
66
                $chunkData = self::sanitizeChunk($rawChunk);
67
                if ($chunkData['key'] == $chunk_key) {
68
                    $content = str_replace($matches[0][$k], '', $content);
69
                    continue;
70
                }
71
                $cacheKey = $content_key . $chunkData['key'] . serialize($chunkData);
72
                switch ($chunkData['token']) {
73
                    case '$':
74
                        if ($preprocess === false) break;
75
                        $chunk = self::fetchChunkByKey($chunkData['key']);
76
                        $replacement = Yii::$app->cache->get($cacheKey);
77
                        if ($replacement === false) {
78
                            $replacement = static::compileChunk($chunk, $chunkData, $chunkData['key'], $content_key, $dependency);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Bug introduced by
Since compileChunk() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of compileChunk() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
79
                            Yii::$app->cache->set(
80
                                $content_key,
81
                                $replacement,
82
                                84600,
83
                                $dependency
84
                            );
85
                        }
86
                        break;
87
                    case '%':
88
                        if ($preprocess === true) {
89
                            $replacement = $rawChunk;
90
                            break;
91
                        }
92
                        $replacement = static::replaceForms($chunkData);
0 ignored issues
show
Bug introduced by
Since replaceForms() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of replaceForms() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
93
                        break;
94
                    case '~' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
95
                        if ($preprocess === false) break;
96
                        $replacement = Yii::$app->cache->get($cacheKey);
97
                        if ($replacement === false) {
98
                            $replacement = static::renderUrl($chunkData);
0 ignored issues
show
Bug introduced by
Since renderUrl() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of renderUrl() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
99
                            Yii::$app->cache->set(
100
                                $content_key,
101
                                $replacement,
102
                                84600,
103
                                $dependency
104
                            );
105
                        }
106
                        break;
107
                }
108
                $content = str_replace($matches[0][$k], $replacement, $content);
109
            }
110
        }
111
        return $content;
112
    }
113
114
    /**
115
     * @param array $chunkData
116
     * @return mixed
117
     */
118
    private static function replaceForms($chunkData)
119
    {
120
        $regexp = '/^(?P<formId>\d+)(#(?P<id>[\w\d\-_]+))?(;(?P<isModal>isModal))?$/Usi';
121
        return preg_replace_callback(
122
            $regexp,
123
            function ($matches) {
124
                if (isset($matches['formId'])) {
125
                    $params = ['formId' => intval($matches['formId'])];
126
                    if (isset($matches['id'])) {
127
                        $params['id'] = $matches['id'];
128
                    }
129
                    if (isset($matches['isModal'])) {
130
                        $params['isModal'] = true;
131
                    }
132
                    return app\widgets\form\Form::widget($params);
133
                }
134
                return '';
135
            },
136
            $chunkData['key']
137
        );
138
    }
139
140
    /**
141
     * renders url according to given data
142
     * @param $chunkData
143
     * @return string
144
     */
145
    private static function renderUrl($chunkData)
146
    {
147
        $expression = '%(?P<objectName>[^#]+?)#(?P<objectId>[\d]+?)$%';
148
        $output = '';
149
        preg_match($expression, $chunkData['key'], $m);
150
        if (true === isset($m['objectName'], $m['objectId'])) {
151
            $id = (int)$m['objectId'];
152
            switch (strtolower($m['objectName'])) {
153 View Code Duplication
                case "page" :
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
154
                    if (null !== $model = app\modules\page\models\Page::findById($id)) {
155
                        $output = Url::to(['@article', 'id' => $id]);
156
                    }
157
                    break;
158
                case "category" :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
159
                    if (null !== $model = app\modules\shop\models\Category::findById($id)) {
160
                        $output = Url::to(['@category', 'last_category_id' => $id]);
161
                    }
162
                    break;
163 View Code Duplication
                case "product" :
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
164
                    if (null !== $model = app\modules\shop\models\Product::findById($id)) {
165
                        $output = Url::to(['@product', 'model' => $model]);
166
                    }
167
                    break;
168
            }
169
        }
170
        return $output;
171
    }
172
173
    /**
174
     * Extracts chunk data from chunk call
175
     * uses regexp to extract param data from placeholder
176
     * [[$chunk <paramName>='<escapedValue>'|'<escapedDefault>' <paramName>=<unescapedValue>|<unescapedDefault>]]
177
     * iterate matches.
178
     * While iterating converts escapedValue and escapedDefault into string, unescapedValue and unescapedDefault - into float
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
179
     * Returns chunk data array like:
180
     *  [
181
     *      'key' => 'chunkKey',
182
     *      'firstParam'=> 'string value',
183
     *      'firstParam-default'=> 'default string value',
184
     *      'secondParam'=> float value,
185
     *      'secondParam-default'=> default float value,
186
     *  ]
187
     *
188
     * @param string $rawChunk
189
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<*,string|double>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
190
     */
191
    private static function sanitizeChunk($rawChunk)
192
    {
193
        $chunk = [];
194
        preg_match('%(?P<chunkToken>[^\w\[]?)([^\s\]\[]+)[\s\]]%', $rawChunk, $keyMatches);
195
        $chunk['token'] = $keyMatches['chunkToken'];
196
        $chunk['key'] = $keyMatches[2];
197
        $expression = "#\s*(?P<paramName>[\\w\\d]*)=(('(?P<escapedValue>.*[^\\\\])')|(?P<unescapedValue>.*))(\\|(('(?P<escapedDefault>.*[^\\\\])')|(?P<unescapedDefault>.*)))?[\\]\\s]#uUi";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 188 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
198
        preg_match_all($expression, $rawChunk, $matches);
199
        foreach ($matches['paramName'] as $key => $paramName) {
200
            if (!empty($matches['escapedValue'][$key])) {
201
                $chunk[$paramName] = strval($matches['escapedValue'][$key]);
202
            }
203
            if (!empty($matches['unescapedValue'][$key])) {
204
                $chunk[$paramName] = floatval($matches['unescapedValue'][$key]);
205
            }
206 View Code Duplication
            if (!empty($matches['escapedDefault'][$key])) {
207
                $chunk[$paramName . '-default'] = strval($matches['escapedDefault'][$key]);
208
            }
209 View Code Duplication
            if (!empty($matches['unescapedDefault'][$key])) {
210
                $chunk[$paramName . '-default'] = floatval($matches['unescapedDefault'][$key]);
211
            }
212
        }
213
        return $chunk;
214
    }
215
216
    /**
217
     * Compiles single chunk
218
     * uses regexp to find placeholders and extract it's data from chunk value field
219
     * [[<token><paramName>:<format><params>]]
220
     * token switch is for future functionality increase
221
     * now method only recognizes + token and replaces following param with according $arguments array data
222
     * applies formatter according previously defined param values type if needed
223
     * if param name from placeholder was not found in arguments array, placeholder in the compiled chunk will be replaced with empty string
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 140 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
224
     * returns compiled chunk
225
     *
226
     * @param  string $content_key Key for caching compiled content version
227
     * @param  yii\caching\Dependency $dependency Cache dependency
228
     * @param  string $chunk ContentBlock instance
229
     * @param  array $arguments Arguments for this chunk from original content
230
     * @param  string $key ContentBlock key string to prevent endless recursion
231
     * @return string Result string ready for replacing
232
     */
233
    private static function compileChunk($chunk, $arguments, $key, $content_key, $dependency)
234
    {
235
        $matches = [];
236
        preg_match_all('%\[\[(?P<token>[\+\*])(?P<paramName>[^\s\:\]]+)\:?(?P<format>[^\,\]]+)?\,?(?P<params>[^\]]+)?\]\]%ui', $chunk, $matches);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
237
        foreach ($matches[0] as $k => $rawParam) {
238
            $token = $matches['token'][$k];
239
            $paramName = trim($matches['paramName'][$k]);
240
            $format = trim($matches['format'][$k]);
241
            $params = preg_replace('%[\s]%', '', $matches['params'][$k]);
242
            $params = explode(',', $params);
243
            switch ($token) {
244
                case '+':
245
                    if (array_key_exists($paramName, $arguments)) {
246
                        $replacement = static::applyFormatter($arguments[$paramName], $format, $params);
0 ignored issues
show
Bug introduced by
Since applyFormatter() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of applyFormatter() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
247
                        $chunk = str_replace($matches[0][$k], $replacement, $chunk);
248
                    } else if (array_key_exists($paramName . '-default', $arguments)) {
249
                        $replacement = static::applyFormatter($arguments[$paramName . '-default'], $format, $params);
0 ignored issues
show
Bug introduced by
Since applyFormatter() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of applyFormatter() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
250
                        $chunk = str_replace($matches[0][$k], $replacement, $chunk);
251
                    } else {
252
                        $chunk = str_replace($matches[0][$k], '', $chunk);
253
                    }
254
                    break;
255
                default:
256
                    $chunk = str_replace($matches[0][$k], '', $chunk);
257
            }
258
        }
259
        return self::processData($chunk, $content_key, $dependency, $key);
260
    }
261
262
    /**
263
     * Find formatter declarations in chunk placeholders. if find trying to apply
264
     * yii\i18n\Formatter formats see yii\i18n\Formatter for details
265
     *
266
     * @param string $value single placeholder declaration from chunk
267
     * @param string $format
268
     * @param array $params
269
     * @return string|array
270
     */
271
    private static function applyFormatter($value, $format, $params)
272
    {
273
        if (false === method_exists(Yii::$app->formatter, $format) || empty($format)) {
274
            return $value;
275
        }
276
        array_unshift($params, $value);
277
        try {
278
            $formattedValue = call_user_func_array([Yii::$app->formatter, $format], $params);
279
        } catch (\Exception $e) {
280
            $formattedValue = $value;
281
        }
282
        return $formattedValue;
283
    }
284
285
    /**
286
     * Fetches single chunk by key from static var
287
     * if is no there - get it from db and push to static array
288
     *
289
     * @param $key string Chunk key field
290
     * @return string Chunk value field
291
     */
292
    private static function fetchChunkByKey($key)
293
    {
294
        if (!array_key_exists($key, static::$chunksByKey)) {
295
            $dependency = new TagDependency([
296
                'tags' => [
297
                    ActiveRecordHelper::getCommonTag(ContentBlock::className()),
298
                ]
299
            ]);
300
            static::$chunksByKey[$key] = ContentBlock::getDb()->cache(function ($db) use ($key) {
0 ignored issues
show
Unused Code introduced by
The parameter $db is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
301
                $chunk = ContentBlock::find()
302
                    ->where(['key' => $key])
303
                    ->asArray()
304
                    ->one();
305
                return static::$chunksByKey[$key] = $chunk['value'];
306
            }, 86400, $dependency);
307
        }
308
        return static::$chunksByKey[$key];
309
    }
310
311
    /**
312
     * preloads chunks with option preload  = 1
313
     * and push it to static array
314
     *
315
     * @return array|void
316
     */
317
    private static function preloadChunks()
318
    {
319
        if (is_null(static::$chunksByKey)) {
320
            $dependency = new TagDependency([
321
                'tags' => [
322
                    ActiveRecordHelper::getCommonTag(ContentBlock::className()),
323
                ]
324
            ]);
325
            static::$chunksByKey = ContentBlock::getDb()->cache(function ($db) {
0 ignored issues
show
Unused Code introduced by
The parameter $db is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
326
                $chunks = ContentBlock::find()
327
                    ->where(['preload' => 1])
328
                    ->asArray()
329
                    ->all();
330
                return ArrayHelper::map($chunks, 'key', 'value');
331
            }, 86400, $dependency);
332
        }
333
        return static::$chunksByKey;
334
    }
335
336
    /**
337
     * renders chunks in template files
338
     * @param string $key ContentBlock key
339
     * @param array $params . Array of params to be replaced while render
340
     * @param yii\base\Model $model . Caller model instance to use in caching
0 ignored issues
show
Documentation introduced by
Should the type for parameter $model not be null|yii\base\Model?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
341
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
342
     */
343
    public static function getChunk($key, $params = [], yii\base\Model $model = null)
344
    {
345
        if (null === $rawChunk = self::fetchChunkByKey($key)) {
346
            return '';
347
        }
348
        $tags = [
349
            ActiveRecordHelper::getCommonTag(app\modules\core\models\ContentBlock::className()),
350
        ];
351
        $content_key = 'templateChunkRender' . $key;
352
        if (null !== $model) {
353
            $content_key .= $model->id;
354
            $tags[] = ActiveRecordHelper::getObjectTag(get_class($model), $model->id);
355
        }
356
        $dependency = new TagDependency(['tags' => $tags]);
357
        if (false === empty($params)) {
358
            $rawChunk = self::compileChunk($rawChunk, $params, $key, $content_key, $dependency);
359
        }
360
        return self::compileContentString($rawChunk, $content_key, $dependency);
361
    }
362
}
363