-
Notifications
You must be signed in to change notification settings - Fork 29
Added $connection property to class #141
Added $connection property to class #141
Conversation
Hello, thank you for your pull request. I will start to process this PR and get back to you if I need any more information. |
* | ||
* @var \Magento\Framework\DB\Adapter\AdapterInterface | ||
*/ | ||
protected $connection = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually looking into this file I cannot see this being used in this class. So what we can do here is remove this variable and the assignment in the constructor. You will have to leave the varaible in the consturctor definition but can add Add @SuppressWarnings(PHPMD.UnusedFormalParameter)
as it will be an unused parameters. For example:
/**
* Construct
*
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Downloadable\Helper\File $fileHelper
* @param \Magento\CatalogImportExport\Model\Import\UploaderFactory $uploaderFactory
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Magento\Framework\Filesystem $filesystem
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Downloadable\Helper\File $fileHelper,
\Magento\CatalogImportExport\Model\Import\UploaderFactory $uploaderFactory,
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Framework\Filesystem $filesystem
) {
parent::__construct($context);
$this->fileHelper = $fileHelper;
$this->fileUploader = $uploaderFactory->create();
$this->fileUploader->init();
$this->fileUploader->setAllowedExtensions($this->getAllowedExtensions());
$this->fileUploader->removeValidateCallback('catalog_product_image');
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
}
We do this to keep from breaking backwards compatibility. More information on this topic can be found on devdocs https://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/
Done. Interesting approach by the way! |
@@ -60,7 +62,6 @@ public function __construct( | |||
$this->fileUploader->init(); | |||
$this->fileUploader->setAllowedExtensions($this->getAllowedExtensions()); | |||
$this->fileUploader->removeValidateCallback('catalog_product_image'); | |||
$this->connection = $resource->getConnection('write'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not allowed to remove public properties, because according to PHP Property Visibility: Methods declared without any explicit visibility keyword are defined as public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah forgot about that. @maxalmonte14 would you be able to add the $connection
as public then in future versions we can deprecate it. But it would be better at least to have it shown and public now. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add the property as public with a default null value, or should I leave the implementation as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add the property without a default and then put this implementation back as it was before. Unless @sidolov thinks best otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, now the $connection
property is public.
@@ -46,6 +51,8 @@ class Uploader extends \Magento\Framework\App\Helper\AbstractHelper | |||
* @param \Magento\CatalogImportExport\Model\Import\UploaderFactory $uploaderFactory | |||
* @param \Magento\Framework\App\ResourceConnection $resource | |||
* @param \Magento\Framework\Filesystem $filesystem | |||
* | |||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess now we do not need this suppress warning since the connection is being set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Description (*)
This PR solves the problem addressed in #137
Fixed Issues (if relevant)
Manual testing scenarios (*)
Run
./vendor/bin/phpstan analyse app/code/Magento/DownloadableImportExport/Helper/Uploader.php
as described in #137, after this implementation the following errors shouldn't be presentContribution checklist (*)