Comments (7)
Damn it, thanks for catching this. I only tested with primitives. Fix looks good, would have done the same. I'll borrow the code and then merge.
Thanks for your contribution!
from phpstan-magento.
Thank you for this bug report. Technically it should not be possible to proxy an interface, that is what classes implementing an interface are for. You cannot use an interface and extend from it, thus the error above is correct.
Does Magento really allow to create proxies for interfaces?
from phpstan-magento.
Yes it does. Below are the contents of the autogenerated file from magento.
generated/code/Magento/Catalog/Api/ProductRepositoryInterface/Proxy.php
<?php
namespace Magento\Catalog\Api\ProductRepositoryInterface;
/**
* Proxy class for @see \Magento\Catalog\Api\ProductRepositoryInterface
*/
class Proxy implements \Magento\Catalog\Api\ProductRepositoryInterface, \Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
*
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $_objectManager = null;
/**
* Proxied instance name
*
* @var string
*/
protected $_instanceName = null;
/**
* Proxied instance
*
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
protected $_subject = null;
/**
* Instance shareability flag
*
* @var bool
*/
protected $_isShared = null;
/**
* Proxy constructor
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param string $instanceName
* @param bool $shared
*/
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\Magento\\Catalog\\Api\\ProductRepositoryInterface', $shared = true)
{
$this->_objectManager = $objectManager;
$this->_instanceName = $instanceName;
$this->_isShared = $shared;
}
/**
* @return array
*/
public function __sleep()
{
return ['_subject', '_isShared', '_instanceName'];
}
/**
* Retrieve ObjectManager from global scope
*/
public function __wakeup()
{
$this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
}
/**
* Clone proxied instance
*/
public function __clone()
{
$this->_subject = clone $this->_getSubject();
}
/**
* Get proxied instance
*
* @return \Magento\Catalog\Api\ProductRepositoryInterface
*/
protected function _getSubject()
{
if (!$this->_subject) {
$this->_subject = true === $this->_isShared
? $this->_objectManager->get($this->_instanceName)
: $this->_objectManager->create($this->_instanceName);
}
return $this->_subject;
}
/**
* {@inheritdoc}
*/
public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
{
return $this->_getSubject()->save($product, $saveOptions);
}
/**
* {@inheritdoc}
*/
public function get($sku, $editMode = false, $storeId = null, $forceReload = false)
{
return $this->_getSubject()->get($sku, $editMode, $storeId, $forceReload);
}
/**
* {@inheritdoc}
*/
public function getById($productId, $editMode = false, $storeId = null, $forceReload = false)
{
return $this->_getSubject()->getById($productId, $editMode, $storeId, $forceReload);
}
/**
* {@inheritdoc}
*/
public function delete(\Magento\Catalog\Api\Data\ProductInterface $product)
{
return $this->_getSubject()->delete($product);
}
/**
* {@inheritdoc}
*/
public function deleteById($sku)
{
return $this->_getSubject()->deleteById($sku);
}
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
return $this->_getSubject()->getList($searchCriteria);
}
}
from phpstan-magento.
Thanks for pointing out. Will check how to fix this.
from phpstan-magento.
Still on this, got a wired side effect due some additional autoloading. Still need to figure out what the source of the problem is...
from phpstan-magento.
@nicojust could you please give #13 a try. Seems to work in my test case, wondering if it would fix your problem as well.
from phpstan-magento.
@shochdoerfer
Thank you for your effort.
Unfortunately it still seems to be causing problems.
In one of my classes i'm injecting the ProductRepositoryInterface via Proxy like this.
ProductHelper
<?php
use Magento\Catalog\Api\ProductRepositoryInterface;
class ProductHelper
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @param ProductRepositoryInterface\Proxy $productRepository
*/
public function __construct(ProductRepositoryInterface\Proxy $productRepository)
{
$this->productRepository = $productRepository;
}
}
While analysing the following error messages pop up.
PHP Warning: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Magento\Catalog\Api\ProductRepositoryInterface\Magento\Catalog\Api\Data\ProductInterface not found and could not be autoloaded. in vendor/phpstan/phpstan/src/Broker/Broker.php:358
PHP Fatal error: Declaration of Magento\Catalog\Api\ProductRepositoryInterface\Proxy::save(Magento\Catalog\Api\ProductRepositoryInterface\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = NULL) must be compatible with Magento\Catalog\Api\ProductRepositoryInterface::save(Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false) in /tmp/PSMP9fViSr on line 6
/tmp/PSMP9fViSr
<?php
namespace Magento\Catalog\Api\ProductRepositoryInterface;
/**
* Proxy class for @see Magento\Catalog\Api\ProductRepositoryInterface
*/
class Proxy implements \Magento\Framework\ObjectManager\NoninterceptableInterface, \Magento\Catalog\Api\ProductRepositoryInterface
{
/**
* @return array
*/
public function __sleep() {}
/**
* Retrieve ObjectManager from global scope
*/
public function __wakeup() {}
/**
* Clone proxied instance
*/
public function __clone() {}
public function save(Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = NULL) {}
public function get($sku, $editMode = NULL, $storeId = NULL, $forceReload = NULL) {}
public function getById($productId, $editMode = NULL, $storeId = NULL, $forceReload = NULL) {}
public function delete(Magento\Catalog\Api\Data\ProductInterface $product) {}
public function deleteById($sku) {}
public function getList(Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) {}
}
I think the problem is that the type hints for parameters are searched within the current namespace.
For example it should be:
public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = NULL) {}
and not
public function save(Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = NULL) {}
I managed to fix it by checking if the provided type is built in or not and prefixing it with \
.
ProxyAutoloader.php:42
$paramType = $parameter->getType() ?: '';
if ($paramType instanceof \ReflectionType) {
if ($paramType->isBuiltin()) {
$paramType = $paramType->getName() . ' ';
} else {
$paramType = '\\' . $paramType->getName() . ' ';
}
}
Not sure if that is the correct way to fix this problem.
from phpstan-magento.
Related Issues (20)
- No coverage data is *not* sent to Coveralls
- Certain CI steps run several times without additional result HOT 1
- Move stubs out of src/ HOT 6
- DateTimeFactory Issue; HOT 6
- Use Magento root for TestFrameworkAutoloader HOT 8
- Project config file at path app/code/Vendor/Module does not exist. HOT 5
- Factory generation misnames output class HOT 4
- Current release version not updated HOT 5
- Wrong directory used as "magentoRoot" when current working direcory is not magento root HOT 2
- private string $magentoRoot; not work in PHP 7.2 HOT 4
- Generated class ProductExtension is passed on incorrectly to phpstan HOT 30
- Missing Interface class HOT 9
- Add support for PHP 8.2 HOT 3
- Compatibility with PHPstan 1.10.x HOT 4
- Failure with `phpstan/phpstan-phpunit` and PHPStan cache usage HOT 19
- Version 0.30.0 fails with errors about unexpected items in parameters HOT 4
- Extend ci_neon_lint script to validate parametersSchema
- Incompatibility with phpstan & rector and 2.4.6 HOT 1
- Internal error: Class\Foo does not exist and has no extension interface in file class.php HOT 2
- Occasional Errors In Pipeline HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpstan-magento.