"Does not accept Doctrine\ORM\EntityRepository" Error in shopware 5 PhpStan analysis - doctrine

I have used the following lines of code in my shopware 5 plugin
use HatslogicAbandonedCartNotification\Models\AbandonedCartItems as AbandonedCartItemsModel;
use HatslogicAbandonedCartNotification\Models\Repository as AbandonedCartItemsRepository;
I have a variable
/ **
  * #var AbandonedCartItemsRepository
  * /
private $abandonedCartItemsRepository;
In the function __construct I set the variable
$this->abandonedCartItemsRepository = $this->modelManager->getRepository (AbandonedCartItemsModel :: class);
But in PHPstan analysis I got the following error
Property HatslogicAbandonedCartNotification \ Subscriber \
CartNotification :: $ abandonedCartItemsRepository
           (HatslogicAbandonedCartNotification \ Models \ Repository) does not accept Doctrine \ ORM \ EntityRepository.
Anything wrong with my code? or is it an ignorable error?

Thank you #Shyim
I have fixed the issue by
/** #var AbandonedCartItemsRepository $abandonedCartItemsRepository */
$abandonedCartItemsRepository = $this->modelManager->getRepository (AbandonedCartItemsModel :: class);
$this->abandonedCartItemsRepository = $abandonedCartItemsRepository;

Just assign it to a variable and make a phpdoc. That should fix it :)
Otherwise try the doctrine phpstan extension

Related

Error when i try to create livewire component

I've installed laravel livewire on a Laravel 8 project, ad when i run the command php artisan make:livewire table the terminal shows this error:
ArgumentCountError
Too few arguments to function Illuminate\Support\Str::finish(), 1 passed in /Applications/MAMP/htdocs/cuoreLaravel/vendor/livewire/livewire/src/helpers.php on line 12 and exactly 2 expected
at vendor/laravel/framework/src/Illuminate/Support/Str.php:235
231▕ * #param string $value
232▕ * #param string $cap
233▕ * #return string
234▕ */
➜ 235▕ public static function finish($value, $cap)
236▕ {
237▕ $quoted = preg_quote($cap, '/');
238▕
239▕ return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
+17 vendor frames
18 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
I've followed all the documentation installation steps, but I don't understand what the problem is.
I hope someone can help me :-) thanks
This happened to me after a fresh install of Livewire. Running php artisan optimize fixed it in my case. I have not found the exact reason, but I suspect some of the Livewire config needed to be included in the config cache first.
So either optimize, or clear the cached config completely.

Unable to mock Cache::put() facade in Laravel

I'm trying to mock the Cache::put() facade. But it gives me an error. I have tried different ways but couldn't figure it out.
public function testGetAllFromDatabase()
{
$industry = new Industry();
Cache::shouldReceive('has')
->once()
->with('industries.all')
->andReturn(false);
Cache::shouldReceive('put')
->with('industries.all', '', 0)
->andReturn(true);
$this->industryMock
->shouldReceive('all')
->once()
->andReturn(array_reverse($this->industries));
$this->app->instance(Industry::class, $this->industryMock);
$industryRepository = new IndustryRepository();
$all = $industryRepository->all();
dd($all);
$this->assertContains( $this->industries[2], $all);
}
But when I execute it the following error is occurring.
$ vendor/bin/phpunit
PHPUnit 7.2.7 by Sebastian Bergmann and contributors.
...E 4 / 4 (100%)
Time: 3.76 seconds, Memory: 12.00MB
There was 1 error:
1) Tests\Unit\RepositoriesTests\IndustryRepositoryTest::testGetAllFromDatabase
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_1_Illuminate_Cache_CacheManager::put('industries.all', object(Illuminate\Database\Eloquent\Collection), '1440'). Either the method was unexpected or its arguments matched no expected argument list for this method
Objects: ( array (
'Illuminate\\Database\\Eloquent\\Collection' =>
array (
'class' => 'Illuminate\\Database\\Eloquent\\Collection',
'properties' =>
array (
),
),
))
F:\development\consulting.local\src\vendor\mockery\mockery\library\Mockery\ExpectationDirector.php:92
F:\development\consulting.local\src\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:223
F:\development\consulting.local\src\app\Repositories\IndustryRepository.php:30
F:\development\consulting.local\src\tests\Unit\RepositoriesTests\IndustryRepositoryTest.php:81
I have tried many ways but couldn't get it to fix. Thank you.
Since it may help others, Laravel's facade includes helper functions that allow swapping then with a Mockery test double
This means that when you use a shouldReceive you can chain it with any Mockery expectation for example in this case if you don't care about some parameters you can use:
Cache::shouldReceive('put')
->with('industries.all', \Mockery::any(), \Mockery::any())
->andReturn(true);
In case it helps others, it's good to point out that you may not want to mock Cache, but instead actually use the real Cache.
That's because it's a Cache for testing only:
When running tests via vendor/bin/phpunit, Laravel [....] automatically configures the session and cache to the array driver while testing, meaning no session or cache data will be persisted while testing.
https://laravel.com/docs/8.x/testing#environment
Note that unlike the OP's test, you may need to follow Laravel's guidance about your test class extending their TestCase to get the behavior, e.g.
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase

Container::getAlias($abstract) throws ErrorException: Illegal offset type in isset or empty when $abstract there is not in $this->aliases[]

Laravel Version: 5.6.16
PHP Version: 7.2.3
Database Driver & Version: N/A
Description:
laravel\framework\src\Illuminate\Container\Container.php public function getAlias($abstract)
throws ErrorException: Illegal offset type in isset or empty
when $abstract there is not in $this->aliases[]
$this->aliases[$abstract] is null and !isset($this->aliases[$abstract]) throws ErrorException: Illegal offset type in isset or empty
$abstract value is Modules\Administration\Tests\Commands\StubJsonCommandHandler
Steps To Reproduce:
Run AdministrationControllerTest (https://github.com/proyectotau/TAU/ clone laraveldusk branch [4ef9b0e124657abed7afde0969f332bf7be95a8b])
Is it a bug or I have any mistake? Thanks in advance!
When binding an instance to the container, please make sure you are using:
app()->instance('dependency', $instantiation);
not,
app()->bind('dependency', $instantiation); // DON'T bind an instance
Attempting to bind an instance will result an error, as the container tries to index possible aliases using a concrete object as opposed to a type.
Workaround
Change in getAlias() function
! isset($this->aliases[$abstract])
for
! isset($this->aliases[(string)$abstract])
Or change explicitly type-hint to string at ALL functions (#param string is not enough)
public function getAlias($abstract)
for
public function getAlias(string $abstract)
But it fails later in next use of [$abstract] in Container:
isShared() at isset($this->instances[(string)$abstract]) isset($this->bindings[(string)$abstract]
resolve() calling to$this->resolved[(string)$abstract] = true;
getConcrete() at if (isset($this->bindings[(string)$abstract]))
getContextualConcrete() at if (empty($this->abstractAliases[(string)$abstract]))
getExtenders() at if (isset($this->extenders[(string)$abstract]))
and in Illuminate\Foundation\Application:
make() at if (isset($this->deferredServices[(string)$abstract]) && ! isset($this->instances[(string)$abstract]))
PS: Please have a look to Alvaro Gonzalez's comment in
php - How do I fix this illegal offset type error
I finally found out the issue was send params like ::class which can not be used as an array index.
Strings must be instead

Maximum function nesting level of '100' reached, aborting! Route Model Binding

My route file
Route::model('rank', 'Rank');
Route::resource('rank', 'AdminRankController');
My Controller file
public function show($rank)
{
return $rank;
}
This give me error Symfony \ Component \ Debug \ Exception \ FatalErrorException
Maximum function nesting level of '100' reached, aborting!
Any Help will be appreciated . Earlier It was working . But My composer update ruined all.
Please note if I change it like
Route::model('ranks', 'Rank');
It is working but no database query runs to fetch the corresponding row

Magento Media Browser Not Appearing

Did an upgrade from 1.5 to 1.6 and now the media browser is not appearing. When I go to a product and try to add some images in the wysiwyg I get the following message when I try to bring it up:
The log reports:
ERR (3): Warning: Missing argument 1 for Mage_Page_Block_Html_Head::addJs() in /var/www/domain.net/app/code/core/Mage/Page/Block/Html/Head.php on line 66
(3): Notice: Undefined variable: name in /var/www/domain.com/app/code/core/Mage/Page/Block/Html/Head.php on line 68
Firebug reports:
"NetworkError: 404 Not Found - http://www.domain.net/skin/m/1346486879/js/mage/adminhtml/variables.js,/js/mage/adminhtml/wysiwyg/widget.js,/js/lib/flex.js,/js/lib/FABridge.js,/js/mage/adminhtml/flexuploader.js,/js/mage/adminhtml/browser.js,/js/"
I checked all the JS files and they all load. The item /js/ at the end appears to be the problem. Looking in the layout main.xml it appears that it might be /js/prototype/window.js
I tried calling /js/prototype/window.js in the template head which did not work. The log error is for a method that adds the JavaScript to the page.
Here is the code that the log is giving errors messages to:
/**
* Add JavaScript file to HEAD entity
*
* #param string $name
* #param string $params
* #return Mage_Page_Block_Html_Head
*/
public function addJs($name, $params = "")
{
$this->addItem('js', $name, $params);
return $this;
}
I finally tracked down the module that was the root of the issue. I saw this issue with custom modules so I figured some module was causing this.
First I turned off all my modules with this command:
find . -name "*.xml" -print | xargs sed -i 's/true/false/g'
Then I tracked it down to: Fooman Speedster
Hope this helps someone else who runs into this issue.

Resources