diff --git a/app/code/Magento/Analytics/Model/Connector/Http/ResponseResolver.php b/app/code/Magento/Analytics/Model/Connector/Http/ResponseResolver.php index 9ae099803ab8..e32b37ef239c 100644 --- a/app/code/Magento/Analytics/Model/Connector/Http/ResponseResolver.php +++ b/app/code/Magento/Analytics/Model/Connector/Http/ResponseResolver.php @@ -31,8 +31,9 @@ public function __construct(ConverterInterface $converter, array $responseHandle } /** - * @param \Zend_Http_Response $response + * Get result from $response. * + * @param \Zend_Http_Response $response * @return bool|string */ public function getResult(\Zend_Http_Response $response) diff --git a/app/code/Magento/Backend/App/Area/FrontNameResolver.php b/app/code/Magento/Backend/App/Area/FrontNameResolver.php index 0738804b5f76..be0cedfc95bf 100644 --- a/app/code/Magento/Backend/App/Area/FrontNameResolver.php +++ b/app/code/Magento/Backend/App/Area/FrontNameResolver.php @@ -10,10 +10,15 @@ use Magento\Backend\Setup\ConfigOptionsList; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\RequestInterface; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\Store; +use Zend\Uri\UriInterface; /** + * Class to get area front name. + * * @api * @since 100.0.2 */ @@ -59,19 +64,35 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver */ private $scopeConfig; + /** + * @var UriInterface + */ + private $uri; + + /** + * @var RequestInterface + */ + private $request; + /** * @param \Magento\Backend\App\Config $config * @param DeploymentConfig $deploymentConfig * @param ScopeConfigInterface $scopeConfig + * @param UriInterface $uri + * @param RequestInterface $request */ public function __construct( \Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + UriInterface $uri = null, + RequestInterface $request = null ) { $this->config = $config; $this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME); $this->scopeConfig = $scopeConfig; + $this->uri = $uri ?: ObjectManager::getInstance()->get(UriInterface::class); + $this->request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class); } /** @@ -104,7 +125,7 @@ public function isHostBackend() } else { $backendUrl = $this->scopeConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE); } - $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; + $host = $this->request->getServer('HTTP_HOST', ''); return stripos($this->getHostWithPort($backendUrl), (string) $host) !== false; } @@ -116,9 +137,11 @@ public function isHostBackend() */ private function getHostWithPort($url) { - $scheme = parse_url(trim($url), PHP_URL_SCHEME); - $host = parse_url(trim($url), PHP_URL_HOST); - $port = parse_url(trim($url), PHP_URL_PORT); + $this->uri->parse($url); + $scheme = $this->uri->getScheme(); + $host = $this->uri->getHost(); + $port = $this->uri->getPort(); + if (!$port) { $port = isset($this->standardPorts[$scheme]) ? $this->standardPorts[$scheme] : null; } diff --git a/app/code/Magento/Braintree/Model/LocaleResolver.php b/app/code/Magento/Braintree/Model/LocaleResolver.php index 5dcd2e8a343e..df6f914ec34b 100644 --- a/app/code/Magento/Braintree/Model/LocaleResolver.php +++ b/app/code/Magento/Braintree/Model/LocaleResolver.php @@ -8,6 +8,9 @@ use Magento\Framework\Locale\ResolverInterface; use Magento\Braintree\Gateway\Config\PayPal\Config; +/** + * Resolve stores locale. + */ class LocaleResolver implements ResolverInterface { /** diff --git a/app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php b/app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php index c3e90c478345..16fc76f81f34 100644 --- a/app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php +++ b/app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php @@ -70,6 +70,7 @@ public function __construct( /** * Gets image name from $value array. + * * Will return empty string in a case when $value is not an array * * @param array $value Attribute value @@ -86,6 +87,7 @@ private function getUploadedImageName($value) /** * Avoiding saving potential upload data to DB + * * Will set empty image attribute value if image was not uploaded * * @param \Magento\Framework\DataObject $object @@ -113,6 +115,8 @@ public function beforeSave($object) } /** + * Get Instance of Category Image Uploader. + * * @return \Magento\Catalog\Model\ImageUploader * * @deprecated 101.0.0 diff --git a/app/code/Magento/Catalog/Model/CategoryManagement.php b/app/code/Magento/Catalog/Model/CategoryManagement.php index ea6d66df3627..bf6f26ebfb10 100644 --- a/app/code/Magento/Catalog/Model/CategoryManagement.php +++ b/app/code/Magento/Catalog/Model/CategoryManagement.php @@ -1,14 +1,14 @@ _session = $session; $this->_backendUrl = $backendUrl; @@ -188,9 +210,14 @@ public function __construct( $this->_storageDatabaseFactory = $storageDatabaseFactory; $this->_directoryDatabaseFactory = $directoryDatabaseFactory; $this->_uploaderFactory = $uploaderFactory; + $this->logger = $logger ?: ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class); $this->_resizeParameters = $resizeParameters; $this->_extensions = $extensions; $this->_dirs = $dirs; + $this->file = $file ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\DriverInterface::class); + $this->ioFile = $ioFile ?: ObjectManager::getInstance()->get( + \Magento\Framework\Filesystem\Io\File::class + ); parent::__construct($data); } @@ -288,9 +315,12 @@ public function getDirsCollection($path) /** * Return files * - * @param string $path Parent directory path - * @param string $type Type of storage, e.g. image, media etc. - * @return \Magento\Framework\Data\Collection\Filesystem + * @param string $path Parent directory path + * @param string $type Type of storage, e.g. image, media etc. + * @return \Magento\Framework\Data\Collection\Filesystem + * + * @throws \Magento\Framework\Exception\FileSystemException + * @throws \Magento\Framework\Exception\LocalizedException */ public function getFilesCollection($path, $type = null) { @@ -328,7 +358,8 @@ public function getFilesCollection($path, $type = null) $item->setName($item->getBasename()); $item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename())); $item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename()); - $item->setSize(filesize($item->getFilename())); + $itemStats = $this->file->stat($item->getFilename()); + $item->setSize($itemStats['size']); $item->setMimeType(\mime_content_type($item->getFilename())); if ($this->isImage($item->getBasename())) { @@ -338,11 +369,15 @@ public function getFilesCollection($path, $type = null) $thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]); } - $size = @getimagesize($item->getFilename()); + try { + $size = getimagesize($item->getFilename()); - if (is_array($size)) { - $item->setWidth($size[0]); - $item->setHeight($size[1]); + if (is_array($size)) { + $item->setWidth($size[0]); + $item->setHeight($size[1]); + } + } catch (\Error $e) { + $this->logger->notice(sprintf("GetImageSize caused error: %s", $e->getMessage())); } } else { $thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX); @@ -589,7 +624,7 @@ public function resizeFile($source, $keepRatio = true) $image->open($source); $image->keepAspectRatio($keepRatio); $image->resize($this->_resizeParameters['width'], $this->_resizeParameters['height']); - $dest = $targetDir . '/' . pathinfo($source, PATHINFO_BASENAME); + $dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)[PATHINFO_BASENAME]; $image->save($dest); if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) { return $dest; @@ -624,7 +659,7 @@ public function getThumbsPath($filePath = false) $thumbnailDir = $this->getThumbnailRoot(); if ($filePath && strpos($filePath, (string) $mediaRootDir) === 0) { - $thumbnailDir .= dirname(substr($filePath, strlen($mediaRootDir))); + $thumbnailDir .= $this->file->getParentDirectory(substr($filePath, strlen($mediaRootDir))); } return $thumbnailDir; @@ -674,7 +709,7 @@ public function isImage($filename) if (!$this->hasData('_image_extensions')) { $this->setData('_image_extensions', $this->getAllowedExtensions('image')); } - $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + $ext = strtolower($this->ioFile->getPathInfo($filename)[PATHINFO_EXTENSION]); return in_array($ext, $this->_getData('_image_extensions')); } diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index e212dea27369..ef0b8b7163ad 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -14,6 +14,9 @@ use Magento\Customer\Model\Form; use Magento\Store\Model\ScopeInterface; +/** + * Provides some configurations for customer. + */ class ConfigProvider implements ConfigProviderInterface { /** @@ -57,7 +60,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function getConfig() { @@ -96,6 +99,8 @@ protected function getLoginUrl() * Whether redirect to login page is required * * @return bool + * + * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function isRedirectRequired() { diff --git a/app/code/Magento/Deploy/Service/Bundle.php b/app/code/Magento/Deploy/Service/Bundle.php index 351413fd05f3..65775917e948 100644 --- a/app/code/Magento/Deploy/Service/Bundle.php +++ b/app/code/Magento/Deploy/Service/Bundle.php @@ -9,8 +9,10 @@ use Magento\Deploy\Package\BundleInterface; use Magento\Deploy\Package\BundleInterfaceFactory; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Filesystem; use Magento\Framework\App\Utility\Files; +use Magento\Framework\Filesystem\Io\File; use Magento\Framework\View\Asset\Repository; use Magento\Framework\View\Asset\RepositoryMap; @@ -76,6 +78,11 @@ class Bundle self::ASSET_TYPE_HTML ]; + /** + * @var File|null + */ + private $file; + /** * Bundle constructor * @@ -83,17 +90,25 @@ class Bundle * @param BundleInterfaceFactory $bundleFactory * @param BundleConfig $bundleConfig * @param Files $files + * + * @param File|null $file + * + * @throws \Magento\Framework\Exception\FileSystemException */ public function __construct( Filesystem $filesystem, BundleInterfaceFactory $bundleFactory, BundleConfig $bundleConfig, - Files $files + Files $files, + File $file = null ) { $this->pubStaticDir = $filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); $this->bundleFactory = $bundleFactory; $this->bundleConfig = $bundleConfig; $this->utilityFiles = $files; + $this->file = $file ?: ObjectManager::getInstance()->get( + \Magento\Framework\Filesystem\Io\File::class + ); } /** @@ -103,14 +118,19 @@ public function __construct( * @param string $theme * @param string $locale * @return void + * + * @throws \Magento\Framework\Exception\FileSystemException + * @throws \Magento\Framework\Exception\LocalizedException */ public function deploy($area, $theme, $locale) { - $bundle = $this->bundleFactory->create([ + $bundle = $this->bundleFactory->create( + [ 'area' => $area, 'theme' => $theme, 'locale' => $locale - ]); + ] + ); // delete all previously created bundle files $bundle->clear(); @@ -140,7 +160,7 @@ public function deploy($area, $theme, $locale) $filePath = substr($sourcePath, strlen($area . '/' . $theme . '/' . $locale) + 1); } - $contentType = pathinfo($filePath, PATHINFO_EXTENSION); + $contentType = $this->file->getPathInfo($filePath)[PATHINFO_EXTENSION]; if (!in_array($contentType, self::$availableTypes)) { continue; } @@ -166,7 +186,7 @@ private function hasMinVersion($filePath) return true; } - $info = pathinfo($filePath); + $info = $this->file->getPathInfo($filePath); if (strpos($filePath, '.min.') !== false) { $this->excludedCache[] = str_replace(".min.{$info['extension']}", ".{$info['extension']}", $filePath); } else { diff --git a/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php b/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php index f0b1d621e5ac..8116717676f5 100644 --- a/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php +++ b/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php @@ -15,6 +15,9 @@ */ namespace Magento\Eav\Model\Entity\Increment; +/** + * Handle alphanumeric ids. + */ class Alphanum extends \Magento\Eav\Model\Entity\Increment\AbstractIncrement { /** diff --git a/app/code/Magento/GraphQl/composer.json b/app/code/Magento/GraphQl/composer.json index 8ea033b49996..166e3f170f2d 100644 --- a/app/code/Magento/GraphQl/composer.json +++ b/app/code/Magento/GraphQl/composer.json @@ -4,7 +4,6 @@ "type": "magento2-module", "require": { "php": "~7.1.3||~7.2.0||~7.3.0", - "magento/module-authorization": "*", "magento/module-eav": "*", "magento/framework": "*" }, diff --git a/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php index 2145f924edee..8dca418a3a6a 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php @@ -9,6 +9,8 @@ */ namespace Magento\Reports\Model\ResourceModel\Product; +use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory; + /** * Products Report collection. * @@ -66,6 +68,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection /** * Collection constructor. + * * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy @@ -90,7 +93,13 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection * @param \Magento\Catalog\Model\Product\Type $productType * @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteResource * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection + * @param ProductLimitationFactory|null $productLimitationFactory + * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool + * @param \Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer|null $tableMaintainer + * @param \Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver|null $priceTableResolver + * @param \Magento\Framework\Indexer\DimensionFactory|null $dimensionFactory * + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -118,7 +127,7 @@ public function __construct( \Magento\Catalog\Model\Product\Type $productType, \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteResource, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory $productLimitationFactory = null, + ProductLimitationFactory $productLimitationFactory = null, \Magento\Framework\EntityManager\MetadataPool $metadataPool = null, \Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer $tableMaintainer = null, \Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver $priceTableResolver = null, diff --git a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php index 6e98f7f04238..ace99369d325 100644 --- a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php +++ b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php @@ -138,7 +138,10 @@ protected function setUp() $this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->connectionMock); $this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock); - $productLimitationFactoryMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory::class) + $productLimitationFactoryMock = $this + ->getMockBuilder( + \Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory::class + ) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/Store/App/Response/Redirect.php b/app/code/Magento/Store/App/Response/Redirect.php index 144d526329c7..455929f1ed8f 100644 --- a/app/code/Magento/Store/App/Response/Redirect.php +++ b/app/code/Magento/Store/App/Response/Redirect.php @@ -7,6 +7,8 @@ */ namespace Magento\Store\App\Response; +use Magento\Framework\App\ObjectManager; + /** * Class Redirect computes redirect urls responses. * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) @@ -47,6 +49,10 @@ class Redirect implements \Magento\Framework\App\Response\RedirectInterface * @var \Magento\Framework\UrlInterface */ protected $_urlBuilder; + /** + * @var \Zend\Uri\UriInterface|null + */ + private $uri; /** * Constructor @@ -57,6 +63,7 @@ class Redirect implements \Magento\Framework\App\Response\RedirectInterface * @param \Magento\Framework\Session\SessionManagerInterface $session * @param \Magento\Framework\Session\SidResolverInterface $sidResolver * @param \Magento\Framework\UrlInterface $urlBuilder + * @param \Zend\Uri\UriInterface|null $uri * @param bool $canUseSessionIdInParam */ public function __construct( @@ -66,6 +73,7 @@ public function __construct( \Magento\Framework\Session\SessionManagerInterface $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\UrlInterface $urlBuilder, + \Zend\Uri\UriInterface $uri = null, $canUseSessionIdInParam = true ) { $this->_canUseSessionIdInParam = $canUseSessionIdInParam; @@ -75,6 +83,7 @@ public function __construct( $this->_session = $session; $this->_sidResolver = $sidResolver; $this->_urlBuilder = $urlBuilder; + $this->uri = $uri ?: ObjectManager::getInstance()->get(\Zend\Uri\UriInterface::class); } /** @@ -121,6 +130,8 @@ public function getRefererUrl() * * @param string $defaultUrl * @return \Magento\Framework\App\ActionInterface + * + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getRedirectUrl($defaultUrl = null) { @@ -134,8 +145,10 @@ public function getRedirectUrl($defaultUrl = null) /** * Redirect to error page * - * @param string $defaultUrl + * @param string $defaultUrl * @return string + * + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function error($defaultUrl) { @@ -154,6 +167,8 @@ public function error($defaultUrl) * * @param string $defaultUrl * @return string + * + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function success($defaultUrl) { @@ -218,21 +233,20 @@ protected function normalizeRefererUrl($refererUrl) return $refererUrl; } - $redirectParsedUrl = parse_url($refererUrl); - $refererQuery = []; + $redirectParsedUrl = $this->uri->parse($refererUrl); - if (!isset($redirectParsedUrl['query'])) { + if (!$redirectParsedUrl->getQuery()) { return $refererUrl; } - parse_str($redirectParsedUrl['query'], $refererQuery); + $refererQuery = $redirectParsedUrl->getQueryAsArray(); $refererQuery = $this->normalizeRefererQueryParts($refererQuery); - $normalizedUrl = $redirectParsedUrl['scheme'] + $normalizedUrl = $redirectParsedUrl->getScheme() . '://' - . $redirectParsedUrl['host'] - . (isset($redirectParsedUrl['port']) ? ':' . $redirectParsedUrl['port'] : '') - . $redirectParsedUrl['path'] + . $redirectParsedUrl->getHost() + . ($redirectParsedUrl->getPort() ? ':' . $redirectParsedUrl->getPort() : '') + . $redirectParsedUrl->getPath() . ($refererQuery ? '?' . http_build_query($refererQuery) : ''); return $normalizedUrl; diff --git a/app/code/Magento/Theme/Helper/Storage.php b/app/code/Magento/Theme/Helper/Storage.php index 4927cd2832e4..20dac80c8b16 100644 --- a/app/code/Magento/Theme/Helper/Storage.php +++ b/app/code/Magento/Theme/Helper/Storage.php @@ -10,8 +10,11 @@ namespace Magento\Theme\Helper; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\ObjectManager; /** + * Handles the storage of media files like images and fonts. + * * @api * @since 100.0.2 * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) @@ -89,17 +92,27 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper */ protected $mediaDirectoryWrite; + /** + * @var \Magento\Framework\Filesystem\Io\File|null + */ + private $file; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Backend\Model\Session $session * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory + * @param \Magento\Framework\Filesystem\Io\File|null $file + * + * @throws \Magento\Framework\Exception\FileSystemException + * @throws \Magento\Framework\Exception\ValidatorException */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Backend\Model\Session $session, - \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory + \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory, + \Magento\Framework\Filesystem\Io\File $file = null ) { parent::__construct($context); $this->filesystem = $filesystem; @@ -107,6 +120,9 @@ public function __construct( $this->_themeFactory = $themeFactory; $this->mediaDirectoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->mediaDirectoryWrite->create($this->mediaDirectoryWrite->getRelativePath($this->getStorageRoot())); + $this->file = $file ?: ObjectManager::getInstance()->get( + \Magento\Framework\Filesystem\Io\File::class + ); } /** @@ -247,7 +263,11 @@ public function getCurrentPath() */ public function getThumbnailDirectory($path) { - return pathinfo($path, PATHINFO_DIRNAME) . '/' . \Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY; + return sprintf( + "%s/%s", + $this->file->getPathInfo($path)[PATHINFO_DIRNAME], + \Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY + ); } /** @@ -260,10 +280,16 @@ public function getThumbnailDirectory($path) public function getThumbnailPath($imageName) { $imagePath = $this->getCurrentPath() . '/' . $imageName; - if (!$this->mediaDirectoryWrite->isExist($imagePath) || 0 !== strpos($imagePath, (string) $this->getStorageRoot())) { + if (!$this->mediaDirectoryWrite->isExist($imagePath) || + 0 !== strpos($imagePath, (string) $this->getStorageRoot()) + ) { throw new \InvalidArgumentException('The image not found.'); } - return $this->getThumbnailDirectory($imagePath) . '/' . pathinfo($imageName, PATHINFO_BASENAME); + return sprintf( + "%s/%s", + $this->getThumbnailDirectory($imagePath), + $this->file->getPathInfo($imageName)[PATHINFO_BASENAME] + ); } /** diff --git a/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php b/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php index b2b4ef506bf4..1a6ddd8e964e 100644 --- a/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php +++ b/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php @@ -8,6 +8,9 @@ use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized; use Magento\Framework\Serialize\Serializer\Json; +/** + * Validate Eav Model before save. + */ class Exceptions extends ArraySerialized { /** @@ -100,12 +103,13 @@ public function beforeSave() * * @param string $search * @return string + * * @throws \Magento\Framework\Exception\LocalizedException on invalid regular expression */ protected function _composeRegexp($search) { // If valid regexp entered - do nothing - if (@preg_match($search, '') !== false) { + if (preg_match($search, '') !== false) { return $search; } @@ -163,6 +167,8 @@ public function afterLoad() } /** + * Get Value from data array. + * * @return array */ public function getValue() diff --git a/app/code/Magento/Theme/Model/Theme/Registration.php b/app/code/Magento/Theme/Model/Theme/Registration.php index 0cef321640ed..e42d8dad77bf 100644 --- a/app/code/Magento/Theme/Model/Theme/Registration.php +++ b/app/code/Magento/Theme/Model/Theme/Registration.php @@ -49,8 +49,8 @@ class Registration /** * Initialize dependencies * - * @param \Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory $collectionFactory - * @param \Magento\Theme\Model\Theme\Data\Collection $filesystemCollection + * @param \Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory $collectionFactory + * @param \Magento\Theme\Model\Theme\Data\Collection $filesystemCollection */ public function __construct( \Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory $collectionFactory, @@ -80,12 +80,14 @@ public function register() /** * Register theme and recursively all its ascendants + * * Second param is optional and is used to prevent circular references in inheritance chain * - * @param ThemeInterface &$theme - * @param array $inheritanceChain - * @return $this - * @throws LocalizedException + * @param ThemeInterface &$theme + * @param array $inheritanceChain + * @return $this + * + * @throws LocalizedException */ protected function _registerThemeRecursively(&$theme, $inheritanceChain = []) { diff --git a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php index de38bfcb1d63..e45867c798d4 100644 --- a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php +++ b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php @@ -7,6 +7,7 @@ namespace Magento\Theme\Model\Wysiwyg; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\ObjectManager; /** * Theme wysiwyg storage model @@ -74,6 +75,10 @@ class Storage * @var \Magento\Framework\Url\DecoderInterface */ protected $urlDecoder; + /** + * @var \Magento\Framework\Filesystem\Io\File|null + */ + private $file; /** * Initialize dependencies @@ -84,6 +89,9 @@ class Storage * @param \Magento\Framework\Image\AdapterFactory $imageFactory * @param \Magento\Framework\Url\EncoderInterface $urlEncoder * @param \Magento\Framework\Url\DecoderInterface $urlDecoder + * @param \Magento\Framework\Filesystem\Io\File|null $file + * + * @throws \Magento\Framework\Exception\FileSystemException */ public function __construct( \Magento\Framework\Filesystem $filesystem, @@ -91,7 +99,8 @@ public function __construct( \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Image\AdapterFactory $imageFactory, \Magento\Framework\Url\EncoderInterface $urlEncoder, - \Magento\Framework\Url\DecoderInterface $urlDecoder + \Magento\Framework\Url\DecoderInterface $urlDecoder, + \Magento\Framework\Filesystem\Io\File $file = null ) { $this->mediaWriteDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->_helper = $helper; @@ -99,6 +108,9 @@ public function __construct( $this->_imageFactory = $imageFactory; $this->urlEncoder = $urlEncoder; $this->urlDecoder = $urlDecoder; + $this->file = $file ?: ObjectManager::getInstance()->get( + \Magento\Framework\Filesystem\Io\File::class + ); } /** @@ -147,7 +159,7 @@ public function _createThumbnail($source) return false; } $thumbnailDir = $this->_helper->getThumbnailDirectory($source); - $thumbnailPath = $thumbnailDir . '/' . pathinfo($source, PATHINFO_BASENAME); + $thumbnailPath = sprintf("%s/%s", $thumbnailDir, $this->file->getPathInfo($source)[PATHINFO_BASENAME]); try { $this->mediaWriteDirectory->isExist($thumbnailDir); $image = $this->_imageFactory->create(); @@ -217,7 +229,9 @@ public function deleteFile($file) $filePath = $this->mediaWriteDirectory->getRelativePath($path . '/' . $file); $thumbnailPath = $this->_helper->getThumbnailDirectory($filePath) . '/' . $file; - if (0 === strpos($filePath, (string) $path) && 0 === strpos($filePath, (string) $this->_helper->getStorageRoot())) { + if (0 === strpos($filePath, (string) $path) && + 0 === strpos($filePath, (string) $this->_helper->getStorageRoot()) + ) { $this->mediaWriteDirectory->delete($filePath); $this->mediaWriteDirectory->delete($thumbnailPath); } @@ -261,7 +275,7 @@ public function getFilesCollection() if (!$this->mediaWriteDirectory->isFile($path)) { continue; } - $fileName = pathinfo($path, PATHINFO_BASENAME); + $fileName = $this->file->getPathInfo($path)[PATHINFO_BASENAME]; $file = ['text' => $fileName, 'id' => $this->urlEncoder->encode($fileName)]; if (self::TYPE_IMAGE == $storageType) { $requestParams['file'] = $fileName; @@ -289,7 +303,10 @@ public function getTreeArray() $resultArray = []; foreach ($directories as $path) { $resultArray[] = [ - 'text' => $this->_helper->getShortFilename(pathinfo($path, PATHINFO_BASENAME), 20), + 'text' => $this->_helper->getShortFilename( + $this->file->getPathInfo($path)[PATHINFO_BASENAME], + 20 + ), 'id' => $this->_helper->convertPathToId($path), 'cls' => 'folder' ]; diff --git a/app/code/Magento/Variable/Ui/Component/VariablesDataProvider.php b/app/code/Magento/Variable/Ui/Component/VariablesDataProvider.php index 12f36f080e48..f685b7dac922 100644 --- a/app/code/Magento/Variable/Ui/Component/VariablesDataProvider.php +++ b/app/code/Magento/Variable/Ui/Component/VariablesDataProvider.php @@ -70,9 +70,12 @@ public function __construct( */ private function sortBy($items, $field, $direction) { - usort($items, function ($item1, $item2) use ($field, $direction) { - return $this->variablesCompare($item1, $item2, $field, $direction); - }); + usort( + $items, + function ($item1, $item2) use ($field, $direction) { + return $this->variablesCompare($item1, $item2, $field, $direction); + } + ); return $items; } @@ -95,7 +98,8 @@ private function variablesCompare($variable1, $variable2, $partIndex, $direction /** * Merge variables from different sources: - * custom variables and default (stores configuration variables) + * + * Custom variables and default (stores configuration variables) * * @return array */ @@ -120,9 +124,14 @@ public function getData() foreach ($filterGroup->getFilters() as $filter) { $value = str_replace('%', '', $filter->getValue()); $filterField = $filter->getField(); - $items = array_values(array_filter($items, function ($item) use ($value, $filterField) { - return strpos(strtolower($item[$filterField]), (string) strtolower($value)) !== false; - })); + $items = array_values( + array_filter( + $items, + function ($item) use ($value, $filterField) { + return strpos(strtolower($item[$filterField]), (string) strtolower($value)) !== false; + } + ) + ); } } diff --git a/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php b/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php index d612a4a8d275..51b474cc215b 100644 --- a/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php +++ b/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php @@ -751,12 +751,14 @@ private function handleComplex($name, $type, $prefix, $isArray) if ($isArray) { $subPrefix .= self::ARRAY_SIGNIFIER; } - $queryNames = array_merge( - $queryNames, - $this->getQueryParamNames($subParameterName, $subParameterType, $subParameterDescription, $subPrefix) + $queryNames[] = $this->getQueryParamNames( + $subParameterName, + $subParameterType, + $subParameterDescription, + $subPrefix ); } - return $queryNames; + return array_merge(...$queryNames); } /** diff --git a/app/code/Magento/WebapiAsync/Controller/Rest/AsynchronousSchemaRequestProcessor.php b/app/code/Magento/WebapiAsync/Controller/Rest/AsynchronousSchemaRequestProcessor.php index f85c58ee0613..313bdb232cc6 100644 --- a/app/code/Magento/WebapiAsync/Controller/Rest/AsynchronousSchemaRequestProcessor.php +++ b/app/code/Magento/WebapiAsync/Controller/Rest/AsynchronousSchemaRequestProcessor.php @@ -13,6 +13,9 @@ use Magento\Framework\Webapi\Request; use Magento\Webapi\Controller\Rest\RequestProcessorInterface; +/** + * Get schema from request to generate swagger body. + */ class AsynchronousSchemaRequestProcessor implements RequestProcessorInterface { /** @@ -25,10 +28,12 @@ class AsynchronousSchemaRequestProcessor implements RequestProcessorInterface * @var \Magento\Webapi\Model\Rest\Swagger\Generator */ private $swaggerGenerator; + /** * @var \Magento\Framework\Webapi\Rest\Response */ private $response; + /** * @var string */ @@ -52,7 +57,13 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc + * + * @return void + * + * @throws \Magento\Framework\Exception\AuthorizationException + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Webapi\Exception */ public function process(\Magento\Framework\Webapi\Rest\Request $request) { @@ -70,7 +81,10 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request) } /** - * {@inheritdoc} + * @inheritdoc + * + * @param \Magento\Framework\Webapi\Rest\Request $request + * @return bool */ public function canProcess(\Magento\Framework\Webapi\Rest\Request $request) { @@ -81,6 +95,8 @@ public function canProcess(\Magento\Framework\Webapi\Rest\Request $request) } /** + * Check if a request is a bulk request. + * * @param \Magento\Framework\Webapi\Rest\Request $request * @return bool */ diff --git a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Simple.php b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Simple.php index 20bb599e1e8e..fb2d8f429088 100644 --- a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Simple.php +++ b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Simple.php @@ -50,7 +50,7 @@ public function __construct(ReadFactory $readFactory, RulePool $rulePool) } /** - * {@inheritdoc} + * @inheritdoc */ public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null) { diff --git a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php index c7bb7f30af41..709be46eac42 100644 --- a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php +++ b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php @@ -5,10 +5,9 @@ */ namespace Magento\Setup\Mvc\Bootstrap; -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\ContainerException; use Magento\Framework\App\Bootstrap as AppBootstrap; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\ObjectManager; use Magento\Framework\App\Request\Http; use Magento\Framework\App\State; use Magento\Framework\Filesystem; @@ -19,16 +18,16 @@ use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; use Zend\Router\Http\RouteMatch; -use Zend\ServiceManager\Exception\ServiceNotCreatedException; -use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use Zend\Stdlib\RequestInterface; +use Zend\Uri\UriInterface; /** * A listener that injects relevant Magento initialization parameters and initializes filesystem * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @codingStandardsIgnoreStart */ class InitParamListener implements ListenerAggregateInterface, FactoryInterface { @@ -53,11 +52,15 @@ class InitParamListener implements ListenerAggregateInterface, FactoryInterface ]; /** - * {@inheritdoc} + * @inheritdoc * * The $priority argument is added to support latest versions of Zend Event Manager. * Starting from Zend Event Manager 3.0.0 release the ListenerAggregateInterface::attach() * supports the `priority` argument. + * + * @param EventManagerInterface $events + * @param int $priority + * @return void */ public function attach(EventManagerInterface $events, $priority = 1) { @@ -73,13 +76,16 @@ public function attach(EventManagerInterface $events, $priority = 1) } /** - * {@inheritdoc} + * @inheritdoc + * + * @param EventManagerInterface $events + * @return void */ public function detach(EventManagerInterface $events) { foreach ($this->listeners as $index => $listener) { - $events->detach($listener); - unset($this->listeners[$index]); + $events->detach($listener); + unset($this->listeners[$index]); } } @@ -110,7 +116,9 @@ public function onBootstrap(MvcEvent $e) * * @param \Zend\Mvc\MvcEvent $event * @return false|\Zend\Http\Response + * * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Setup\Exception */ public function authPreDispatch($event) { @@ -189,7 +197,10 @@ private function getSetupCookiePath(\Magento\Framework\ObjectManagerInterface $o } /** - * {@inheritdoc} + * @inheritdoc + * + * @param ServiceLocatorInterface $serviceLocator + * @return mixed */ public function createService(ServiceLocatorInterface $serviceLocator) { diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/DataOptionTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/DataOptionTest.php index 264bde3a9440..89831dd1471f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/DataOptionTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/DataOptionTest.php @@ -59,7 +59,6 @@ public function setUp() ->willReturn($this->mvcEvent); $this->mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); $this->mvcEvent->expects($this->any())->method('getName')->willReturn('dispatch'); - } public function testIndexAction() diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/EnvironmentTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/EnvironmentTest.php index 105bcbce325d..aa16ea1f8cd6 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/EnvironmentTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/EnvironmentTest.php @@ -307,5 +307,5 @@ protected function getMvcEventMock( $mvcEvent->expects($this->any())->method('getName')->willReturn('dispatch'); return $mvcEvent; -} + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php index c87b7fa10d9a..d0fd62adc42b 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php @@ -215,7 +215,6 @@ public function testDispatch() $mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); $mvcEvent->expects($this->any())->method('getName')->willReturn('dispatch'); - $contentArray = '{"config": { "address": { "base_url": "http://123.45.678.12"}}}'; $request->expects($this->any())->method('getContent')->willReturn($contentArray); $this->controller->setEvent($mvcEvent); diff --git a/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php b/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php index 990893dfa909..79717ab55558 100644 --- a/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php @@ -304,10 +304,20 @@ public function testAuthPreDispatch() $routeMatchMock->expects($this->exactly(2)) ->method('getParam') - ->willReturnMap([ - ['controller', null, 'testController'], - ['action', null, 'testAction'] - ]); + ->willReturnMap( + [ + [ + 'controller', + null, + 'testController' + ], + [ + 'action', + null, + 'testAction' + ] + ] + ); $eventMock->expects($this->once()) ->method('getRouteMatch') ->willReturn($routeMatchMock); @@ -437,10 +447,20 @@ public function testAuthPreDispatchSkip() ->method('isAvailable'); $routeMatchMock->expects($this->exactly(2)) ->method('getParam') - ->willReturnMap([ - ['controller', null, \Magento\Setup\Controller\Session::class], - ['action', null, 'unlogin'] - ]); + ->willReturnMap( + [ + [ + 'controller', + null, + \Magento\Setup\Controller\Session::class + ], + [ + 'action', + null, + 'unlogin' + ] + ] + ); $eventMock->expects($this->once()) ->method('getRouteMatch') ->willReturn($routeMatchMock);