Skip to content

Commit a4e3f9a

Browse files
committed
AC-6437:Ensure PHP8.1 Support after 7.4 removal - Handled null errors for pathinfo
1 parent 65ca3aa commit a4e3f9a

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

app/code/Magento/Deploy/Collector/Collector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function collect()
9393
if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule())) {
9494
continue;
9595
}
96-
$file->setDeployedFileName($this->fileNameResolver->resolve($file->getFileName()));
96+
$file->setDeployedFileName($this->fileNameResolver->resolve($file->getFileName() ?? ''));
9797
$params = $this->getParams($file);
9898
$packagePath = "{$params['area']}/{$params['theme']}/{$params['locale']}";
9999
if (!isset($packages[$packagePath])) {

app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function process(Package $package, array $options)
9595
if ($packageFile && $packageFile->getOrigPackage() === $package) {
9696
continue;
9797
}
98-
$deployFileName = $this->fileNameResolver->resolve($file->getFileName());
98+
$deployFileName = $this->fileNameResolver->resolve($file->getFileName() ?? '');
9999
if ($deployFileName !== $file->getFileName()) {
100100
if ($this->hasOverrides($file, $package)) {
101101
$file = clone $file;

app/code/Magento/Deploy/Service/DeployStaticFile.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Deploy\Service;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Exception\FileSystemException;
10+
use Magento\Framework\Exception\LocalizedException;
911
use Magento\Framework\Filesystem;
1012
use Magento\Framework\Filesystem\File\WriteInterface;
1113
use Magento\Framework\View\Asset\Minification;
@@ -83,8 +85,9 @@ public function __construct(
8385
* @param string $fileName
8486
* @param array $params ['area' =>, 'theme' =>, 'locale' =>, 'module' =>]
8587
* @return string
88+
* @throws LocalizedException
8689
*/
87-
public function deployFile($fileName, array $params = [])
90+
public function deployFile(string $fileName, array $params = []): string
8891
{
8992
$params['publish'] = true;
9093
$asset = $this->assetRepo->createAsset($this->resolveFile($fileName), $params);
@@ -97,8 +100,9 @@ public function deployFile($fileName, array $params = [])
97100
/**
98101
* @param string $path
99102
* @return void
103+
* @throws FileSystemException
100104
*/
101-
public function deleteFile($path)
105+
public function deleteFile(string $path)
102106
{
103107
if ($this->pubStaticDir->isExist($path)) {
104108
$absolutePath = $this->pubStaticDir->getAbsolutePath($path);
@@ -120,8 +124,9 @@ public function deleteFile($path)
120124
* @param string $fileName
121125
* @param string $filePath
122126
* @return string|false
127+
* @throws FileSystemException
123128
*/
124-
public function readFile($fileName, $filePath)
129+
public function readFile(string $fileName, string $filePath): bool|string
125130
{
126131
$fileName = $this->minification->addMinifiedSign($fileName);
127132
$relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
@@ -137,7 +142,7 @@ public function readFile($fileName, $filePath)
137142
* @param string $filePath
138143
* @return WriteInterface
139144
*/
140-
public function openFile($fileName, $filePath)
145+
public function openFile(string $fileName, string $filePath): WriteInterface
141146
{
142147
$relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
143148
return $this->pubStaticDir->openFile($relativePath, 'w+');
@@ -150,8 +155,9 @@ public function openFile($fileName, $filePath)
150155
* @param string $filePath
151156
* @param string $content
152157
* @return int The number of bytes that were written.
158+
* @throws FileSystemException
153159
*/
154-
public function writeFile($fileName, $filePath, $content)
160+
public function writeFile(string $fileName, string $filePath, string $content): int
155161
{
156162
$relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
157163
return $this->pubStaticDir->writeFile($relativePath, $content);
@@ -164,8 +170,9 @@ public function writeFile($fileName, $filePath, $content)
164170
* @param string $sourcePath
165171
* @param string $targetPath
166172
* @return bool
173+
* @throws FileSystemException
167174
*/
168-
public function copyFile($fileName, $sourcePath, $targetPath)
175+
public function copyFile(string $fileName, string $sourcePath, string $targetPath): bool
169176
{
170177
$fileName = $this->minification->addMinifiedSign($fileName);
171178
return $this->pubStaticDir->copyFile(
@@ -179,9 +186,10 @@ public function copyFile($fileName, $sourcePath, $targetPath)
179186
*
180187
* @param string $fileName
181188
* @param string $filePath
182-
* @return string
189+
* @return bool|string
190+
* @throws FileSystemException
183191
*/
184-
public function readTmpFile($fileName, $filePath)
192+
public function readTmpFile(string $fileName, string $filePath): bool|string
185193
{
186194
$relativePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
187195
return $this->tmpDir->isFile($relativePath) ? $this->tmpDir->readFile($relativePath) : false;
@@ -194,10 +202,12 @@ public function readTmpFile($fileName, $filePath)
194202
* @param string $filePath
195203
* @param string $content
196204
* @return int The number of bytes that were written.
205+
* @throws FileSystemException
197206
*/
198-
public function writeTmpFile($fileName, $filePath, $content)
207+
public function writeTmpFile(string $fileName, string $filePath, string $content): int
199208
{
200209
$relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
210+
201211
return $this->tmpDir->writeFile($relativePath, $content);
202212
}
203213

@@ -207,14 +217,12 @@ public function writeTmpFile($fileName, $filePath, $content)
207217
* @param string $fileName
208218
* @return string
209219
*/
210-
private function resolveFile($fileName)
220+
private function resolveFile(string $fileName): string
211221
{
212-
$compiledFile = str_replace(
222+
return str_replace(
213223
Repository::FILE_ID_SEPARATOR,
214224
'/',
215225
$this->fileNameResolver->resolve($fileName)
216226
);
217-
218-
return $compiledFile;
219227
}
220228
}

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public function getParamType(ParameterReflection $param)
547547
return strpos($paramType, '[]') !== false ? $paramType : "{$paramType}[]";
548548
}
549549

550-
return $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $type);
550+
return $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $type ?? '');
551551
}
552552

553553
/**

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,17 @@ function (AlternativeSourceInterface $alternativeSource) {
3636
* @param string $fileName
3737
* @return string
3838
*/
39-
public function resolve($fileName)
39+
public function resolve(string $fileName): string
4040
{
4141
$compiledFile = $fileName;
4242
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
4343
foreach ($this->alternativeSources as $name => $alternative) {
44-
if ($alternative->isExtensionSupported($extension)
45-
&& strpos(basename($fileName), '_') !== 0
46-
) {
47-
$compiledFile = $fileName !== null
48-
? substr($fileName, 0, strlen($fileName) - strlen($extension) - 1)
49-
: '';
50-
$compiledFile = $compiledFile . '.' . $name;
44+
if ($alternative->isExtensionSupported($extension) && !str_starts_with(basename($fileName), '_')) {
45+
$compiledFile = substr($fileName, 0, strlen($fileName) - strlen($extension) - 1);
46+
$compiledFile = sprintf('%s.%s', $compiledFile, $name);
5147
}
5248
}
49+
5350
return $compiledFile;
5451
}
5552
}

0 commit comments

Comments
 (0)