GithubHelp home page GithubHelp logo

Comments (10)

mabar avatar mabar commented on June 3, 2024

I tried to solve it via .phpstorm.meta.php which resolves warning when assigning to private UserRepository $userRepository;, but phpstorm still thinks it is UserRepository|IRepository and acts like with IRepository

<?php declare(strict_types = 1);

namespace PHPSTORM_META;

override(
	\Nextras\Orm\Model\IModel::getRepository(0),
	type(0)
);

from orm-intellij.

hrach avatar hrach commented on June 3, 2024

What does it mean to "act slike with IRepository"?
It works for me. Also try please

override(\Nextras\Orm\Model\IModel::getRepository(0), map(['' => '@']));

which may be more correct.

from orm-intellij.

mabar avatar mabar commented on June 3, 2024

What does it mean to "act slike with IRepository"?

It's the type phpstorm shows when I am inspecting property type via ctrl and mouse pointer over $this->userRepository

Check the following example - in comments are types which phpstorm thinks variables have

use Nextras\Orm\Model\IModel;
use OriCMF\Core\User\UserRepository;

final class Test
{

	private IModel $model;

	private UserRepository $userRepository;

	public function __construct(IModel $model)
	{
		$this->model = $model;
		$this->userRepository = $model->getRepository(UserRepository::class);
	}

	public function test(): void
	{
		// $this->userRepository is IRepository|UserRepository
		// $user1 is IEntity
		$user1 = $this->userRepository->getByIdChecked(1);

		// $collection is ICollection
		$collection = $this->userRepository->findAll();
		// $user is mixed
		foreach ($collection as $user) {

		}
	}

}

Your syntax has the same problem. I think it should even be equal, mine is just syntax sugar from newer phpstorm release.

from orm-intellij.

mabar avatar mabar commented on June 3, 2024

phpstorm meta just helped me to get rid of warning Incompatible types: Expected property of type '\OriCMF\Core\User\UserRepository', '\Nextras\Orm\Repository\IRepository' provided and got the repository-specific methods to work, but calling any findBy* and getBy* methods result only into IEntity (even to mixed in ICollection) and also the conditions autocomplete in findBy() and getBy() does not work.
I guess the plugin does not play well with the union type? But I understand it's phpstorm error, because the IRepository type in property with UserRepository type is impossible.

from orm-intellij.

hrach avatar hrach commented on June 3, 2024

Thanks for detailed description, the failing resolution over class property was plugin's bug.

from orm-intellij.

hrach avatar hrach commented on June 3, 2024

Released as 0.8.0. Either wait for the review from JB, or use the zip in the release:
https://github.com/nextras/orm-intellij/releases/tag/v0.8.0

from orm-intellij.

mabar avatar mabar commented on June 3, 2024

Thanks, it works as expected, in combination with .phpstorm.meta.php

from orm-intellij.

mabar avatar mabar commented on June 3, 2024

I just found that one minor issue is still left, assignment of repository to variable is needed.

With variable assignment, $user is User

$userRepository = $this->model->getRepository(UserRepository::class);
$user = $userRepository->getByIdChecked(1);
assert($user instanceof User);

Without variable assignment, $user is IEntity

$user = $this->model->getRepository(UserRepository::class)->getByIdChecked(1);
assert($user instanceof IEntity);

from orm-intellij.

hrach avatar hrach commented on June 3, 2024

Create new issue please.

from orm-intellij.

hrach avatar hrach commented on June 3, 2024

Phpstorm meta added to repo: nextras/orm@f0d67ae

from orm-intellij.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.