| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Ultimate), 4.0.2 |
| Language level | PHP 7.4

EA complains, that \JsonSerializable doesn't contain all methods of my class (or I misunderstand the error).
PHP provided interfaces should be excluded from that check
PhpStorm 2019.2.4
Build #PS-192.7142.41, built on October 30, 2019
Licensed to Fabian Blechschmidt
You have a perpetual fallback license for this version
Subscription is active until October 14, 2020
Runtime version: 11.0.4+10-b304.77 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.1
GC: ParNew, ConcurrentMarkSweep
Memory: 2014M
Cores: 4
Registry: run.processes.with.pty=TRUE, debugger.watches.in.variables=false, php.brace.alt.syntax=true
Non-Bundled Plugins: DBN, Dilbert, PHPUnit code coverage, Remote call, String Manipulation, SvgViewer 2, com.alayouni.ansiHighlight, com.apptorium.TeaCode-IJP-Helper, com.intellij.ideolog, com.ppolivka.gitlabprojects, com.jetbrains.upsource, ideanginx9, krasa.IdeaIconPack, mobi.hsz.idea.gitignore, net.seesharpsoft.intellij.plugins.csv, org.intellij.RegexpTester, Magicento, NEON support, com.kalessil.phpStorm.phpInspectionsEA, com.kalessil.phpStorm.phpInspectionsUltimate, com.magicento2.magicento2, de.espend.idea.php.phpunit, de.espend.idea.php.toolbox, de.espend.idea.php.annotation, de.espend.idea.php.generics, net.king2500.plugins.PhpAdvancedAutoComplete, com.magento.idea.magento2plugin, izhangzhihao.rainbow.brackets, fr.adrienbrault.idea.symfony2plugin, de.espend.idea.oxid, org.mule.tooling.intellij.raml, org.psliwa.idea.composer, org.toml.lang, ru.adelf.idea.dotenv
This is an expected behavior. Actually, the inspection "PHP | Php Inspections (EA Ultimate) | Architecture | Contracts (interfaces) violations" is activated. It requires that all public methods (and maybe protected) being part of the contract/interface.
In your case, as you implements only the \JsonSerializable, it expects that all your public methods should be defined by this interface. Once it is impossible, you should create a new interface and implements it addionally (or disable the inspection).
Board implements addFigure() and getFigureFromPosition(), but it is not declared in an implemented interface. If you won't disable this inspection, it should be a solution:
interface FigureManipulatorContract {
public function addFigure(FigureLikeContract $figureLike): void;
public function getFigureFromPosition(int $position): ?FigureLikeContract;
}
class Board
implements \JsonSerializable,
FigureManipulatorContract {
/* ... implements here ... */
}
Thanks @rentalhost for your answer <3 So the intention is, if I use ANY interface, I'm bound to a full class/interface contract? I would love to have that on my own interfaces.
So when I'm implementing any user land interface I think this is great, but PHP provided interfaces like JsonSerializable and all SPL interfaces on https://www.php.net/manual/en/book.spl.php should be excluded from that.
But I understand that and implemented as you described.
And thank you very much. I understood that the problem is already implementing the interface, instead of having a Serializer class - so this pushes me for better code :D
I'll close the ticket because my problem is solved, if you think it is worth changing, feel free to reopen it :-)
Most helpful comment
This is an expected behavior. Actually, the inspection "PHP | Php Inspections (EA Ultimate) | Architecture | Contracts (interfaces) violations" is activated. It requires that all public methods (and maybe protected) being part of the contract/interface.
In your case, as you implements only the
\JsonSerializable, it expects that all your public methods should be defined by this interface. Once it is impossible, you should create a new interface and implements it addionally (or disable the inspection).BoardimplementsaddFigure()andgetFigureFromPosition(), but it is not declared in an implemented interface. If you won't disable this inspection, it should be a solution: