Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 2 additions & 224 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -23292,60 +23292,6 @@ parameters:
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesCorrect\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesCorrectUnsorted\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$actualValue with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$expectedValue with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$propertyName with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$sortArray with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertStructPropertiesCorrect\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertStructPropertiesCorrect\(\) has parameter \$additionalProperties with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:createFolder\(\) has parameter \$names with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -23388,48 +23334,18 @@ parameters:
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:sortItems\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:sortItems\(\) has parameter \$items with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:updateFolder\(\) has parameter \$names with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^PHPDoc tag @param references unknown parameter\: \$propertyNames$#'
identifier: parameter.notFound
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^PHPDoc tag @var for variable \$searchHandler contains unknown class Ibexa\\Solr\\Handler\.$#'
identifier: class.notFound
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Parameter \#1 \$string1 of function strcmp expects string, bool\|float\|int\|string given\.$#'
identifier: argument.type
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Parameter \#2 \$string2 of function strcmp expects string, bool\|float\|int\|string given\.$#'
identifier: argument.type
count: 1
path: tests/integration/Core/Repository/BaseTestCase.php

-
message: '#^Property Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:\$repository \(Ibexa\\Contracts\\Core\\Repository\\Repository\) does not accept null\.$#'
identifier: assign.propertyType
Expand Down Expand Up @@ -31663,146 +31579,8 @@ parameters:
path: tests/integration/Core/Repository/LanguageServiceMaximumSupportedLanguagesTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language'' and Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Language will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 3
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\LanguageCreateStruct'' and Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\LanguageCreateStruct will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:loadLanguagesReturnsAnEmptyArrayByDefault\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageInTransactionWithCommit\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageInTransactionWithRollback\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageSetsExpectedProperties\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageSetsIdPropertyOnReturnedLanguage\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageThrowsInvalidArgumentException\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testDeleteLanguage\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testDeleteLanguageThrowsInvalidArgumentException\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testDisableLanguage\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testEnableLanguage\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testGetDefaultLanguageCode\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguage\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageById\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageByIdThrowsNotFoundException\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageThrowsInvalidArgumentException\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageThrowsNotFoundException\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguages\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testNewLanguageCreateStruct\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageName\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageNameInTransactionWithCommit\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageNameInTransactionWithRollback\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageNameThrowsInvalidArgumentException\(\) has no return type specified\.$#'
identifier: missingType.return
message: '#^Argument of an invalid type Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: tests/integration/Core/Repository/LanguageServiceTest.php

Expand Down
2 changes: 1 addition & 1 deletion phpunit-integration-legacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<ini name="error_reporting" value="-1"/>
<env name="DATABASE_URL" value="sqlite://:memory:"/>
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Core\Test\IbexaTestKernel"/>
<env name="KERNEL_CLASS" value="Ibexa\Tests\Integration\Core\CoreTestKernel" />
<env name="SEARCH_ENGINE" value="legacy"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
</php>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\Contracts\Core\Repository\Values\Content;

use Ibexa\Contracts\Core\Repository\Values\ValueObject;
use Symfony\Component\Validator\Constraints as Assert;

/**
* This class represents a value for creating a language.
Expand All @@ -18,13 +19,16 @@ class LanguageCreateStruct extends ValueObject
/**
* The languageCode code.
*
* Needs to be a unique.
* Needs to be unique.
*/
#[Assert\NotBlank]
#[Assert\Regex('~^[a-zA-Z\_\-]+$~')]
public ?string $languageCode = null;
Comment on lines +24 to 26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we making a slight BC break here? Or maybe we are validating if later on on the UI side? POV ping @alongosz.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it can be a BC break if someone has migrations that were executing successfully until this regular expression assertion is introduced.

That said, as mentioned in the Jira ticket, creating certain languages (for example, with . as code) breaks the application entirely.


/**
* Human-readable name of the language.
*/
#[Assert\NotBlank]
public ?string $name = null;

/**
Expand Down
10 changes: 4 additions & 6 deletions src/contracts/Validation/StructValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

use Symfony\Component\Validator\Validator\ValidatorInterface;

final class StructValidator
final readonly class StructValidator
{
private ValidatorInterface $validator;

public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
public function __construct(
private ValidatorInterface $validator
) {
}

/**
Expand Down
21 changes: 10 additions & 11 deletions src/lib/Repository/LanguageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Ibexa\Contracts\Core\Repository\Repository as RepositoryInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
use Ibexa\Contracts\Core\Repository\Values\Content\LanguageCreateStruct;
use Ibexa\Contracts\Core\Validation\StructValidator;
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
use Ibexa\Core\Base\Exceptions\InvalidArgumentValue;
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
Expand All @@ -36,9 +37,6 @@ class LanguageService implements LanguageServiceInterface
/** @var array */
protected $settings;

/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */
private $permissionResolver;

/**
* Setups service with reference to repository object that created it & corresponding handler.
*
Expand All @@ -49,12 +47,12 @@ class LanguageService implements LanguageServiceInterface
public function __construct(
RepositoryInterface $repository,
Handler $languageHandler,
PermissionResolver $permissionResolver,
array $settings = []
private readonly PermissionResolver $permissionResolver,
private readonly StructValidator $validator,
array $settings = [],
) {
$this->repository = $repository;
$this->languageHandler = $languageHandler;
$this->permissionResolver = $permissionResolver;
// Union makes sure default settings are ignored if provided in argument
$this->settings = $settings + [
'languages' => ['eng-GB'],
Expand All @@ -64,12 +62,9 @@ public function __construct(
/**
* Creates the a new Language in the content repository.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\LanguageCreateStruct $languageCreateStruct
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Language
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException If user does not have access to content translations
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if the languageCode already exists
* @throws \Ibexa\Contracts\Core\Validation\ValidationFailedException
*/
public function createLanguage(LanguageCreateStruct $languageCreateStruct): Language
{
Expand All @@ -92,10 +87,12 @@ public function createLanguage(LanguageCreateStruct $languageCreateStruct): Lang
sprintf('language with the "%s" language code already exists', $languageCreateStruct->languageCode)
);
}
} catch (APINotFoundException $e) {
} catch (APINotFoundException) {
// Do nothing
}

$this->validator->assertValidStruct('$languageCreateStruct', $languageCreateStruct, ['create']);

$createStruct = new CreateStruct(
[
'languageCode' => $languageCreateStruct->languageCode,
Expand All @@ -104,6 +101,8 @@ public function createLanguage(LanguageCreateStruct $languageCreateStruct): Lang
]
);

$this->validator->assertValidStruct('$languageCreateStruct', $createStruct, ['create']);

$this->repository->beginTransaction();
try {
$createdLanguage = $this->languageHandler->create($createStruct);
Expand Down
Loading
Loading