forked from mglaman/phpstan-drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mglaman/main
Add TranslatableInterface stub (mglaman#588)
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Drupal\Core\TypedData; | ||
|
||
interface TranslatableInterface { | ||
|
||
/** | ||
* @param string $langcode | ||
* @return static | ||
*/ | ||
public function getTranslation(string $langcode): static; | ||
|
||
/** | ||
* @return static | ||
*/ | ||
public function getUntranslated(): static; | ||
|
||
/** | ||
* @param string $langcode | ||
* @param array<string, mixed> $values | ||
* @return static | ||
*/ | ||
public function addTranslation(string $langcode, array $values = []): static; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace mglaman\PHPStanDrupal\Tests\Type; | ||
|
||
use mglaman\PHPStanDrupal\Tests\AdditionalConfigFilesTrait; | ||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
final class ContentEntityTranslationTypeTest extends TypeInferenceTestCase | ||
{ | ||
use AdditionalConfigFilesTrait; | ||
|
||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from self::gatherAssertTypes(__DIR__ . '/data/content-entity-translation.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* @param string $assertType | ||
* @param string $file | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args | ||
): void { | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace DrupalContentEntityTranslation; | ||
|
||
use Drupal\node\Entity\Node; | ||
use Drupal\taxonomy\Entity\Term; | ||
use function PHPStan\Testing\assertType; | ||
|
||
assertType(Node::class, $node = Node::create(['type' => 'page', 'title' => 'foo'])); | ||
assertType(Node::class, $node->getTranslation('en')); | ||
assertType(Node::class, $node->getUntranslated()); | ||
assertType(Node::class, $node->addTranslation('de', ['title' => 'baz'])); | ||
|
||
assertType(Term::class, $node = Term::create(['vid' => 'test', 'name' => 'foo'])); | ||
assertType(Term::class, $node->getTranslation('en')); | ||
assertType(Term::class, $node->getUntranslated()); | ||
assertType(Term::class, $node->addTranslation('de', ['title' => 'baz'])); |