Skip to content

Commit 1b0cec6

Browse files
anzinandrewbess
authored andcommitted
AC-3161: fixed logic affected by "RFC: Deprecate passing null"
1 parent 629e9d9 commit 1b0cec6

File tree

13 files changed

+83
-52
lines changed

13 files changed

+83
-52
lines changed

lib/internal/Magento/Framework/View/Asset.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public function __construct(
7070
}
7171

7272
/**
73+
* Retrieves filename.
74+
*
7375
* @return string
7476
*/
7577
public function getFileName()
@@ -78,6 +80,8 @@ public function getFileName()
7880
}
7981

8082
/**
83+
* Retrieves file ID.
84+
*
8185
* @return string
8286
*/
8387
public function getFileId()
@@ -89,6 +93,8 @@ public function getFileId()
8993
}
9094

9195
/**
96+
* Retrieves file path.
97+
*
9298
* @return string
9399
*/
94100
public function getFilePath()
@@ -100,6 +106,8 @@ public function getFilePath()
100106
}
101107

102108
/**
109+
* Retrieves source path.
110+
*
103111
* @return string
104112
*/
105113
public function getSourcePath()
@@ -108,6 +116,8 @@ public function getSourcePath()
108116
}
109117

110118
/**
119+
* Retrieves module.
120+
*
111121
* @return string
112122
*/
113123
public function getModule()
@@ -116,6 +126,8 @@ public function getModule()
116126
}
117127

118128
/**
129+
* Retrieves area.
130+
*
119131
* @return string
120132
*/
121133
public function getArea()
@@ -124,6 +136,8 @@ public function getArea()
124136
}
125137

126138
/**
139+
* Retrieves theme.
140+
*
127141
* @return string
128142
*/
129143
public function getTheme()
@@ -132,6 +146,8 @@ public function getTheme()
132146
}
133147

134148
/**
149+
* Retrieves locale.
150+
*
135151
* @return string
136152
*/
137153
public function getLocale()
@@ -140,12 +156,16 @@ public function getLocale()
140156
}
141157

142158
/**
159+
* Retrieves file extension.
160+
*
143161
* @return string
144162
*/
145163
public function getExtension()
146164
{
147165
if (!$this->extension) {
148-
$this->extension = strtolower(pathinfo($this->getFileName(), PATHINFO_EXTENSION));
166+
$this->extension = $this->getFileName() !== null
167+
? strtolower(pathinfo($this->getFileName(), PATHINFO_EXTENSION))
168+
: '';
149169
}
150170
return $this->extension;
151171
}

lib/internal/Magento/Framework/View/Asset/Bundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected function getAssetContent(LocalInterface $asset)
230230
if (!isset($this->assetsContent[$assetContextCode][$assetContentType][$assetKey])) {
231231
$content = $asset->getContent();
232232
if (mb_detect_encoding($content) !== "UTF-8") {
233-
$content = mb_convert_encoding($content, "UTF-8");
233+
$content = $content !== null ? mb_convert_encoding($content, "UTF-8") : '';
234234
}
235235
$this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = $content;
236236
}

lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121
class Manager
2222
{
23-
const BUNDLE_JS_DIR = 'js/bundle';
23+
public const BUNDLE_JS_DIR = 'js/bundle';
2424

25-
const BUNDLE_PATH = '/js/bundle/bundle';
25+
public const BUNDLE_PATH = '/js/bundle/bundle';
2626

27-
const ASSET_TYPE_JS = 'js';
27+
public const ASSET_TYPE_JS = 'js';
2828

29-
const ASSET_TYPE_HTML = 'html';
29+
public const ASSET_TYPE_HTML = 'html';
3030

3131
/**
3232
* @var \Magento\Framework\Filesystem
@@ -127,7 +127,7 @@ protected function isExcludedDirectory($directoryPath, $asset)
127127
/** @var $asset LocalInterface */
128128
$directoryPathInfo = $this->splitPath($directoryPath);
129129
if ($directoryPathInfo && $this->compareModules($directoryPathInfo, $asset)) {
130-
return strpos($assetDirectory, $directoryPathInfo['excludedPath']) === 0;
130+
return strpos($assetDirectory, $directoryPathInfo['excludedPath'] ?? '') === 0;
131131
}
132132
return false;
133133
}
@@ -175,7 +175,7 @@ protected function compareModules($filePathInfo, $asset)
175175
*/
176176
protected function splitPath($path)
177177
{
178-
if (strpos($path, '::') !== false) {
178+
if ($path && strpos($path, '::') !== false) {
179179
list($excludedModule, $excludedPath) = explode('::', $path);
180180
return [
181181
'excludedModule' => $excludedModule,
@@ -215,7 +215,7 @@ protected function isAssetMinification(LocalInterface $asset)
215215
return false;
216216
}
217217

218-
if (strpos($sourceFile, '.min.') === false) {
218+
if ($sourceFile && strpos($sourceFile, '.min.') === false) {
219219
$info = pathinfo($asset->getPath());
220220
$assetMinifiedPath = $info['dirname'] . '/' . $info['filename'] . '.min.' . $info['extension'];
221221
if ($this->filesystem->getDirectoryRead(DirectoryList::APP)->isExist($assetMinifiedPath)) {

lib/internal/Magento/Framework/View/Asset/File.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,31 @@ public function __construct(
8181
}
8282

8383
/**
84-
* {@inheritdoc}
84+
* @inheritdoc
8585
*/
8686
public function getUrl()
8787
{
8888
return $this->context->getBaseUrl() . $this->getPath();
8989
}
9090

9191
/**
92-
* {@inheritdoc}
92+
* @inheritdoc
9393
*/
9494
public function getSourceUrl()
9595
{
9696
return $this->context->getBaseUrl() . $this->getRelativeSourceFilePath();
9797
}
9898

9999
/**
100-
* {@inheritdoc}
100+
* @inheritdoc
101101
*/
102102
public function getContentType()
103103
{
104104
return $this->contentType;
105105
}
106106

107107
/**
108-
* {@inheritdoc}
108+
* @inheritdoc
109109
*/
110110
public function getPath()
111111
{
@@ -118,7 +118,7 @@ public function getPath()
118118
}
119119

120120
/**
121-
* {@inheritdoc}
121+
* @inheritdoc
122122
*/
123123
public function getRelativeSourceFilePath()
124124
{
@@ -127,7 +127,7 @@ public function getRelativeSourceFilePath()
127127
if ($sourcePath) {
128128
$origExt = pathinfo($path, PATHINFO_EXTENSION);
129129
$ext = pathinfo($sourcePath, PATHINFO_EXTENSION);
130-
$path = str_replace('.' . $origExt, '.' . $ext, $this->filePath);
130+
$path = $this->filePath !== null ? str_replace('.' . $origExt, '.' . $ext, $this->filePath) : '';
131131
}
132132
$result = '';
133133
$result = $this->join($result, $this->context->getPath());
@@ -149,7 +149,8 @@ private function join($path, $item)
149149
}
150150

151151
/**
152-
* {@inheritdoc}
152+
* @inheritdoc
153+
*
153154
* @throws File\NotFoundException if file cannot be resolved
154155
*/
155156
public function getSourceFile()
@@ -178,7 +179,7 @@ public function getSourceContentType()
178179
}
179180

180181
/**
181-
* {@inheritdoc}
182+
* @inheritdoc
182183
*/
183184
public function getContent()
184185
{
@@ -190,15 +191,16 @@ public function getContent()
190191
}
191192

192193
/**
193-
* {@inheritdoc}
194+
* @inheritdoc
194195
*/
195196
public function getFilePath()
196197
{
197198
return $this->filePath;
198199
}
199200

200201
/**
201-
* {@inheritdoc}
202+
* @inheritdoc
203+
*
202204
* @return File\Context
203205
*/
204206
public function getContext()
@@ -207,7 +209,7 @@ public function getContext()
207209
}
208210

209211
/**
210-
* {@inheritdoc}
212+
* @inheritdoc
211213
*/
212214
public function getModule()
213215
{

lib/internal/Magento/Framework/View/Asset/Minification.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class Minification
1818
/**
1919
* XML path for asset minification configuration
2020
*/
21-
const XML_PATH_MINIFICATION_ENABLED = 'dev/%s/minify_files';
21+
public const XML_PATH_MINIFICATION_ENABLED = 'dev/%s/minify_files';
2222

23-
const XML_PATH_MINIFICATION_EXCLUDES = 'dev/%s/minify_exclude';
23+
public const XML_PATH_MINIFICATION_EXCLUDES = 'dev/%s/minify_exclude';
2424

2525
/**
2626
* @var ScopeConfigInterface
@@ -88,7 +88,8 @@ public function addMinifiedSign($filename)
8888
!$this->isExcluded($filename) &&
8989
!$this->isMinifiedFilename($filename)
9090
) {
91-
$filename = substr($filename, 0, -strlen($extension)) . 'min.' . $extension;
91+
$filename = $filename !== null ? substr($filename, 0, -strlen($extension)) : '';
92+
$filename = $filename . 'min.' . $extension;
9293
}
9394
return $filename;
9495
}
@@ -107,7 +108,8 @@ public function removeMinifiedSign($filename)
107108
!$this->isExcluded($filename) &&
108109
$this->isMinifiedFilename($filename)
109110
) {
110-
$filename = substr($filename, 0, -strlen($extension) - 4) . $extension;
111+
$filename = $filename !== null ? substr($filename, 0, -strlen($extension) - 4) : '';
112+
$filename = $filename . $extension;
111113
}
112114
return $filename;
113115
}
@@ -120,7 +122,7 @@ public function removeMinifiedSign($filename)
120122
*/
121123
public function isMinifiedFilename($filename)
122124
{
123-
return substr($filename, strrpos($filename, '.') - 4, 5) == '.min.';
125+
return $filename && substr($filename, strrpos($filename, '.') - 4, 5) == '.min.';
124126
}
125127

126128
/**
@@ -132,7 +134,7 @@ public function isMinifiedFilename($filename)
132134
public function isExcluded($filename)
133135
{
134136
foreach ($this->getExcludes(pathinfo($filename, PATHINFO_EXTENSION)) as $exclude) {
135-
if (preg_match('/' . str_replace('/', '\/', $exclude) . '/', $filename)) {
137+
if ($filename && preg_match('/' . str_replace('/', '\/', $exclude) . '/', $filename)) {
136138
return true;
137139
}
138140
}
@@ -152,7 +154,7 @@ public function getExcludes($contentType)
152154
$key = sprintf(self::XML_PATH_MINIFICATION_EXCLUDES, $contentType);
153155
$excludeValues = $this->getMinificationExcludeValues($key);
154156
foreach ($excludeValues as $exclude) {
155-
if (trim($exclude) != '') {
157+
if ($exclude && trim($exclude) != '') {
156158
$this->configCache[self::XML_PATH_MINIFICATION_EXCLUDES][$contentType][] = trim($exclude);
157159
}
158160
}
@@ -173,7 +175,7 @@ private function getMinificationExcludeValues($key)
173175
if (!is_array($configValues)) {
174176
$configValuesFromString = [];
175177
foreach (explode("\n", $configValues) as $exclude) {
176-
if (trim($exclude) != '') {
178+
if ($exclude && trim($exclude) != '') {
177179
$configValuesFromString[] = trim($exclude);
178180
}
179181
}
@@ -221,7 +223,7 @@ private function getAreaFromPath(string $filename): string
221223
{
222224
$area = '';
223225
$pathParts = explode('/', $filename);
224-
if (!empty($pathParts) && isset($pathParts[0])) {
226+
if (isset($pathParts[0])) {
225227
$area = $pathParts[0];
226228
}
227229
return $area;

lib/internal/Magento/Framework/View/Asset/NotationResolver/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(Asset\Repository $assetRepo)
4040
*/
4141
public function convertModuleNotationToPath(Asset\LocalInterface $thisAsset, $relatedFileId)
4242
{
43-
if (false === strpos($relatedFileId, Asset\Repository::FILE_ID_SEPARATOR)) {
43+
if (!$relatedFileId || false === strpos($relatedFileId, Asset\Repository::FILE_ID_SEPARATOR)) {
4444
return $relatedFileId;
4545
}
4646
$thisPath = $thisAsset->getPath();

lib/internal/Magento/Framework/View/Asset/NotationResolver/Variable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class Variable
1616
/**
1717
* Regex matching {{placeholders}}
1818
*/
19-
const VAR_REGEX = '/{{([_a-z]*)}}/si';
19+
public const VAR_REGEX = '/{{([_a-z]*)}}/si';
2020

2121
/**
2222
* Provides the combined base url and base path from the asset context
2323
*/
24-
const VAR_BASE_URL_PATH = 'base_url_path';
24+
public const VAR_BASE_URL_PATH = 'base_url_path';
2525

2626
/**
2727
* @var \Magento\Framework\View\Asset\Repository
@@ -52,7 +52,7 @@ public function convertVariableNotation($path)
5252
$replacements[$match[0]] = $this->getPlaceholderValue($match[1]);
5353
}
5454
}
55-
$path = str_replace(array_keys($replacements), $replacements, $path);
55+
$path = $path !== null ? str_replace(array_keys($replacements), $replacements, $path) : '';
5656
}
5757
return $path;
5858
}

lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
use Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder;
1313

1414
/**
15-
* Class AlternativeSource
16-
*
1715
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1816
*/
1917
class AlternativeSource implements AlternativeSourceInterface
2018
{
2119
/**
2220
* The key name of the processor class
2321
*/
24-
const PROCESSOR_CLASS = 'class';
22+
public const PROCESSOR_CLASS = 'class';
2523

2624
/**
2725
* @var Helper\SortInterface
@@ -100,7 +98,7 @@ public function process(Chain $chain)
10098
{
10199
$path = $chain->getAsset()->getFilePath();
102100
$content = $chain->getContent();
103-
if (trim($content) !== '') {
101+
if ($content && trim($content) !== '') {
104102
return;
105103
}
106104

@@ -155,7 +153,7 @@ private function processContent($path, $content, $module, FallbackContext $conte
155153
}
156154
$content = $processor->processContent($asset);
157155

158-
if (trim($content) !== '') {
156+
if ($content && trim($content) !== '') {
159157
return $content;
160158
}
161159
}

0 commit comments

Comments
 (0)