diff --git a/.changelog/current/2468-update-code-styling.md b/.changelog/current/2468-update-code-styling.md new file mode 100644 index 000000000..267f4ae38 --- /dev/null +++ b/.changelog/current/2468-update-code-styling.md @@ -0,0 +1,3 @@ +# Maintenance + +- Update code styling of PHP files in accordance to Nextcloud preference diff --git a/composer.lock b/composer.lock index ff4064d15..181dae34e 100644 --- a/composer.lock +++ b/composer.lock @@ -180,16 +180,16 @@ }, { "name": "nextcloud/coding-standard", - "version": "v1.2.1", + "version": "v1.2.3", "source": { "type": "git", "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e" + "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e", - "reference": "cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/bc9c53a5306114b60c4363057aff9c2ed10a54da", + "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da", "shasum": "" }, "require": { @@ -215,9 +215,9 @@ "description": "Nextcloud coding standards for the php cs fixer", "support": { "issues": "https://github.com/nextcloud/coding-standard/issues", - "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.1" + "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.3" }, - "time": "2024-02-01T14:54:37+00:00" + "time": "2024-08-23T14:32:32+00:00" }, { "name": "nextcloud/ocp", @@ -432,16 +432,16 @@ }, { "name": "php-cs-fixer/shim", - "version": "v3.49.0", + "version": "v3.62.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/shim.git", - "reference": "f7d3219cac46632f12362c9aa7c2ac0d2fe92c52" + "reference": "7a91d5ce45c486f5b445d95901228507a02f60ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/f7d3219cac46632f12362c9aa7c2ac0d2fe92c52", - "reference": "f7d3219cac46632f12362c9aa7c2ac0d2fe92c52", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/7a91d5ce45c486f5b445d95901228507a02f60ae", + "reference": "7a91d5ce45c486f5b445d95901228507a02f60ae", "shasum": "" }, "require": { @@ -478,9 +478,9 @@ "description": "A tool to automatically fix PHP code style", "support": { "issues": "https://github.com/PHP-CS-Fixer/shim/issues", - "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.49.0" + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.62.0" }, - "time": "2024-02-02T00:42:09+00:00" + "time": "2024-08-07T17:03:46+00:00" }, { "name": "php-webdriver/webdriver", diff --git a/lib/Db/RecipeDb.php b/lib/Db/RecipeDb.php index ed75eebf6..97310eccb 100755 --- a/lib/Db/RecipeDb.php +++ b/lib/Db/RecipeDb.php @@ -48,7 +48,7 @@ public function findRecipeById(int $id) { $cursor->closeCursor(); if ($row === false) { - throw new DoesNotExistException($this->l->t("Recipe with ID %d was not found in database.", [$id])); + throw new DoesNotExistException($this->l->t('Recipe with ID %d was not found in database.', [$id])); } $ret = []; @@ -177,7 +177,7 @@ public function findAllKeywords(string $user_id) { $cursor->closeCursor(); $result = array_map(function ($x) { - $x['recipe_count'] = (int) $x['recipe_count']; + $x['recipe_count'] = (int)$x['recipe_count']; return $x; }, $result); @@ -206,7 +206,7 @@ public function findAllCategories(string $user_id) { $cursor->closeCursor(); $result = array_map(function ($x) { - $x['recipe_count'] = (int) $x['recipe_count']; + $x['recipe_count'] = (int)$x['recipe_count']; return $x; }, $result); @@ -235,7 +235,7 @@ public function findAllCategories(string $user_id) { $result[] = [ 'name' => '*', - 'recipe_count' => (int) $row['cnt'] + 'recipe_count' => (int)$row['cnt'] ]; $result = array_unique($result, SORT_REGULAR); @@ -271,21 +271,21 @@ public function getRecipesByCategory(string $category, string $user_id) { $qb->orderBy('r.name'); } else { $qb->select(['r.recipe_id', 'r.name', 'r.date_created', 'r.date_modified', 'k.name AS keywords']) - ->from(self::DB_TABLE_RECIPES, 'r') - ->leftJoin('r', self::DB_TABLE_KEYWORDS, 'k', 'r.recipe_id = k.recipe_id') - ->leftJoin( - 'r', - self::DB_TABLE_CATEGORIES, - 'c', - $qb->expr()->andX( - 'r.user_id = c.user_id', - 'r.recipe_id = c.recipe_id' + ->from(self::DB_TABLE_RECIPES, 'r') + ->leftJoin('r', self::DB_TABLE_KEYWORDS, 'k', 'r.recipe_id = k.recipe_id') + ->leftJoin( + 'r', + self::DB_TABLE_CATEGORIES, + 'c', + $qb->expr()->andX( + 'r.user_id = c.user_id', + 'r.recipe_id = c.recipe_id' + ) ) - ) - ->where( - $qb->expr()->eq('r.user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)), - $qb->expr()->isNull('c.name') - ); + ->where( + $qb->expr()->eq('r.user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)), + $qb->expr()->isNull('c.name') + ); } $cursor = $qb->execute(); @@ -400,7 +400,7 @@ public function findRecipes(array $keywords, string $user_id) { /** * @param array $results Array of recipes with double entries for different keywords - * Group recipes by id and convert keywords to comma-separated list + * Group recipes by id and convert keywords to comma-separated list */ public function groupKeywordInResult(array $result) { $recipesGroupedTags = []; @@ -477,7 +477,7 @@ public function deleteRecipes(array $ids, string $userId) { $qb->orWhere( $qb->expr()->andX( $qb->expr()->eq('recipe_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)), - $qb->expr()->eq("user_id", $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) )); } @@ -574,8 +574,8 @@ public function getCategoryOfRecipe(int $recipeId, string $userId) { $qb = $this->db->getQueryBuilder(); $qb->select('name') - ->from(self::DB_TABLE_CATEGORIES) - ->where('recipe_id = :rid', 'user_id = :uid'); + ->from(self::DB_TABLE_CATEGORIES) + ->where('recipe_id = :rid', 'user_id = :uid'); $qb->setParameter('rid', $recipeId); $qb->setParameter('uid', $userId); diff --git a/lib/Helper/Filter/JSON/ExtractImageUrlFilter.php b/lib/Helper/Filter/JSON/ExtractImageUrlFilter.php index 22fce247a..656470ee5 100644 --- a/lib/Helper/Filter/JSON/ExtractImageUrlFilter.php +++ b/lib/Helper/Filter/JSON/ExtractImageUrlFilter.php @@ -81,7 +81,7 @@ public function apply(array &$json): bool { $regex = preg_match_all('/\d+/', $img, $matches); if ($regex !== false && $regex > 0) { - $sum = array_sum(array_map(fn ($x) => ((int) $x), $matches[0])); + $sum = array_sum(array_map(fn ($x) => ((int)$x), $matches[0])); if ($sum > $maxSum) { $json['image'] = $img; diff --git a/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php b/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php index a037fd6ed..777bd3020 100644 --- a/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php +++ b/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php @@ -51,7 +51,7 @@ public function apply(array &$json): bool { } if (is_float($json[self::YIELD]) || is_double($json[self::YIELD])) { - $json[self::YIELD] = (int) $json[self::YIELD]; + $json[self::YIELD] = (int)$json[self::YIELD]; return true; } @@ -82,7 +82,7 @@ public function apply(array &$json): bool { $count )); - $json[self::YIELD] = (int) $last; + $json[self::YIELD] = (int)$last; return true; } diff --git a/lib/Helper/Filter/JSON/FixToolsFilter.php b/lib/Helper/Filter/JSON/FixToolsFilter.php index 65290a23d..a5cf278b8 100644 --- a/lib/Helper/Filter/JSON/FixToolsFilter.php +++ b/lib/Helper/Filter/JSON/FixToolsFilter.php @@ -51,7 +51,7 @@ public function apply(array &$json): bool { $t = $this->textCleaner->cleanUp($t, false); // Empty string would mean no tools (i.e., empty array) - if($t != "") { + if($t != '') { $tools[] = $t; } } else { diff --git a/lib/Helper/Filter/JSON/SchemaConformityFilter.php b/lib/Helper/Filter/JSON/SchemaConformityFilter.php index 5e1ec1803..920869665 100644 --- a/lib/Helper/Filter/JSON/SchemaConformityFilter.php +++ b/lib/Helper/Filter/JSON/SchemaConformityFilter.php @@ -12,6 +12,6 @@ public function apply(array &$json): bool { $changed |= $this->setJSONValue($json, '@context', 'http://schema.org'); $changed |= $this->setJSONValue($json, '@type', 'Recipe'); - return (bool) $changed; + return (bool)$changed; } } diff --git a/lib/Helper/ISO8601DurationHelper.php b/lib/Helper/ISO8601DurationHelper.php index d039411e2..e4686914b 100644 --- a/lib/Helper/ISO8601DurationHelper.php +++ b/lib/Helper/ISO8601DurationHelper.php @@ -64,8 +64,8 @@ private function parseIsoFormat(string $duration): string { // $matches[5] is the tome part of the string (like T4H5M6S) // $matches[6] to $matches[8] is hours to seconds (like 4H 5M 6S) $hours = (int)$matches[6]; - $minutes = (int) ($matches[7] ?? 0); - $seconds = (int) ($matches[8] ?? 0); + $minutes = (int)($matches[7] ?? 0); + $seconds = (int)($matches[8] ?? 0); while ($seconds >= 60) { $seconds -= 60; diff --git a/lib/Helper/TextCleanupHelper.php b/lib/Helper/TextCleanupHelper.php index 5d5153612..65289d741 100644 --- a/lib/Helper/TextCleanupHelper.php +++ b/lib/Helper/TextCleanupHelper.php @@ -29,7 +29,7 @@ public function cleanUp( $str = str_replace("\t", ' ', $str); if($removeBackslashes) { - $str = str_replace("\\", '_', $str); + $str = str_replace('\\', '_', $str); } // We want to remove forward-slashes for the name of the recipe, to tie it to the directory structure, which cannot have slashes diff --git a/lib/Helper/TimestampHelper.php b/lib/Helper/TimestampHelper.php index a9836a3f8..a4ce951b8 100644 --- a/lib/Helper/TimestampHelper.php +++ b/lib/Helper/TimestampHelper.php @@ -90,7 +90,7 @@ private function parseIsoFormat(string $timestamp): string { * @throws InvalidTimestampException if $timestamp does not comply to ISO 8601 with week and weekday. */ private function parseIsoCalendarDateFormat(string $timestamp, string $dateSeparator = '-'): string { - $date = "Y".$dateSeparator."m".$dateSeparator."d"; + $date = 'Y'.$dateSeparator.'m'.$dateSeparator.'d'; return $this->parseIsoTimestampWithTimeFormats($timestamp, $date); } @@ -143,19 +143,19 @@ private function parseIsoWeekDateFormat(string $timestamp, string $dateSeparator */ private function parseIsoTimestampWithTimeFormats(string $timestamp, string $dateFormat): string { // Try parsing timestamp without milliseconds - $dt = DateTimeImmutable::createFromFormat($dateFormat . "\\TH:i:sP", $timestamp); + $dt = DateTimeImmutable::createFromFormat($dateFormat . '\\TH:i:sP', $timestamp); if($dt) { return $dt->format(self::OUTPUT_FORMAT); } // Try parsing timestamp with dot-separated milliseconds - $dt = DateTimeImmutable::createFromFormat($dateFormat . "\\TH:i:s.vP", $timestamp); + $dt = DateTimeImmutable::createFromFormat($dateFormat . '\\TH:i:s.vP', $timestamp); if($dt) { return $dt->format(self::OUTPUT_FORMAT); } // Try parsing timestamp with comma-separated milliseconds - $dt = DateTimeImmutable::createFromFormat($dateFormat . "\\TH:i:s,vP", $timestamp); + $dt = DateTimeImmutable::createFromFormat($dateFormat . '\\TH:i:s,vP', $timestamp); if($dt) { return $dt->format(self::OUTPUT_FORMAT); } diff --git a/lib/Service/DbCacheService.php b/lib/Service/DbCacheService.php index 66ecebc51..0cc73afcf 100644 --- a/lib/Service/DbCacheService.php +++ b/lib/Service/DbCacheService.php @@ -160,7 +160,7 @@ private function parseJSONFile(File $jsonFile): array { throw new InvalidJSONFileException($this->l->t('The JSON file in the folder with ID %d does not have a valid name.', [$id])); } - $id = (int) $jsonFile->getParent()->getId(); + $id = (int)$jsonFile->getParent()->getId(); $json['id'] = $id; $json = $this->normalizeFileFilter->filter($json, $jsonFile, true); diff --git a/lib/Service/RecipeService.php b/lib/Service/RecipeService.php index a20459fd1..2f07b5db8 100755 --- a/lib/Service/RecipeService.php +++ b/lib/Service/RecipeService.php @@ -389,7 +389,7 @@ public function updateSearchIndex() { $this->migrateFolderStructure(); } catch (UserFolderNotWritableException $ex) { // Ignore migration if not permitted. - $this->logger->warning("Cannot migrate cookbook file structure as not permitted."); + $this->logger->warning('Cannot migrate cookbook file structure as not permitted.'); throw $ex; } } diff --git a/tests/Integration/AbstractDatabaseTestCase.php b/tests/Integration/AbstractDatabaseTestCase.php index a7c240ddb..947de881d 100644 --- a/tests/Integration/AbstractDatabaseTestCase.php +++ b/tests/Integration/AbstractDatabaseTestCase.php @@ -34,7 +34,7 @@ protected function tearDown(): void { } private function resetDataFolder() { - $cmd = "rsync -a --delete --delete-delay /dumps/current/plain/data/ /var/www/html/data"; + $cmd = 'rsync -a --delete --delete-delay /dumps/current/plain/data/ /var/www/html/data'; $output = []; $ret = 0; exec($cmd, $output, $ret); diff --git a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php index 079cae037..47fa1a7f8 100644 --- a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php +++ b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php @@ -415,7 +415,7 @@ public function testUpdateNoName(): void { $data = ['a', 'new', 'array']; - $errorMsg = "No name was given for the recipe."; + $errorMsg = 'No name was given for the recipe.'; $ex = new NoRecipeNameGivenException($errorMsg); $this->restParser->method('getParameters')->willReturn($data); @@ -433,7 +433,7 @@ public function testUpdateConflictingName(): void { $recipe = ['a', 'recipe', 'as', 'array']; - $errorMsg = "Another recipe with that name already exists"; + $errorMsg = 'Another recipe with that name already exists'; $ex = new RecipeExistsException($errorMsg); $this->restParser->method('getParameters')->willReturn($recipe); @@ -476,7 +476,7 @@ public function testCreateNoName(): void { $recipe = ['a', 'recipe', 'as', 'array']; $this->restParser->method('getParameters')->willReturn($recipe); - $errorMsg = "The error that was triggered"; + $errorMsg = 'The error that was triggered'; $ex = new NoRecipeNameGivenException($errorMsg); $this->recipeService->expects($this->once())->method('addRecipe')->with($recipe)->willThrowException($ex); @@ -516,13 +516,13 @@ public function testShow(): void { $id = 123; $recipe = [ - 'name' => "My Name", + 'name' => 'My Name', 'description' => 'a useful description', 'id' => $id, ]; $this->recipeService->method('getRecipeById')->with($id)->willReturn($recipe); $this->recipeService->method('getPrintImage')->willReturn(true); - $imageUrl = "/path/to/image/of/id/123"; + $imageUrl = '/path/to/image/of/id/123'; $this->urlGenerator->method('linkToRoute')->with( 'cookbook.recipe.image', diff --git a/tests/Unit/Helper/FileSystem/RecipeNameHelperTest.php b/tests/Unit/Helper/FileSystem/RecipeNameHelperTest.php index ae2a2f8d2..29aa2e1cd 100644 --- a/tests/Unit/Helper/FileSystem/RecipeNameHelperTest.php +++ b/tests/Unit/Helper/FileSystem/RecipeNameHelperTest.php @@ -34,7 +34,7 @@ public function dpGetFolderName() { '102 chars' => ["{$ninetyChars}123456789012", "{$ninetyChars}1234567___"], '105 chars' => ["{$ninetyChars}123456789012345", "{$ninetyChars}1234567___"], 'special chars' => ['a/b:c?d!e"f|g\\h\'i^j&k#l', 'a_b_c_d_e_f_g_h_i_j_k_l'], - 'greek chars' => ["Τραγανή granola χωρίς ζάχαρη με ό,τι ξηρούς καρπούς & αποξηραμένα φρούτα έχεις στο ντουλάπι σου", "Τραγανή granola χωρίς ζάχαρη με ό,τι ξηρούς καρπούς _ αποξηραμένα φρούτα έχεις στο ντουλάπι σου"], + 'greek chars' => ['Τραγανή granola χωρίς ζάχαρη με ό,τι ξηρούς καρπούς & αποξηραμένα φρούτα έχεις στο ντουλάπι σου', 'Τραγανή granola χωρίς ζάχαρη με ό,τι ξηρούς καρπούς _ αποξηραμένα φρούτα έχεις στο ντουλάπι σου'], ]; } diff --git a/tests/Unit/Helper/Filter/DB/RecipeNameLengthFilterTest.php b/tests/Unit/Helper/Filter/DB/RecipeNameLengthFilterTest.php index e8a7a7315..4e8db9e8f 100644 --- a/tests/Unit/Helper/Filter/DB/RecipeNameLengthFilterTest.php +++ b/tests/Unit/Helper/Filter/DB/RecipeNameLengthFilterTest.php @@ -21,7 +21,7 @@ public function dp() { yield ['abc', 'abc', false]; yield ['äöü', 'äöü', false]; - $tenChars = "0123456789"; + $tenChars = '0123456789'; $twentyChars = "$tenChars$tenChars"; $fiftyChars = $twentyChars . $twentyChars . $tenChars; $hundredTwenty = $fiftyChars . $fiftyChars . $twentyChars; diff --git a/tests/Unit/Helper/Filter/JSON/FixDescriptionFilterTest.php b/tests/Unit/Helper/Filter/JSON/FixDescriptionFilterTest.php index bff9eea33..a5176f4aa 100644 --- a/tests/Unit/Helper/Filter/JSON/FixDescriptionFilterTest.php +++ b/tests/Unit/Helper/Filter/JSON/FixDescriptionFilterTest.php @@ -47,9 +47,9 @@ public function testNonExisting() { public function dpApply() { return [ - ["abc", "abc", "abc", false], + ['abc', 'abc', 'abc', false], ["abc\n\ndef", "abc\n\ndef", "abc\n\ndef", false], - ["abc\n\n", "abc\n\n", "abc", true], + ["abc\n\n", "abc\n\n", 'abc', true], // ["abc\n\n", "abc", true], ]; } diff --git a/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php b/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php index 665c17b06..1ed47ef71 100644 --- a/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php +++ b/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php @@ -47,8 +47,8 @@ public function dp() { [3.4,3,true], [[2], 2, true], [[4.6], 4, true], - ["3", 3, true], - ["123 456", 456, true], + ['3', 3, true], + ['123 456', 456, true], [[4,5], 5, true], ['', 1, true], ['one two three', 1, true], diff --git a/tests/Unit/Helper/Filter/JSON/TimezoneFixFilterTest.php b/tests/Unit/Helper/Filter/JSON/TimezoneFixFilterTest.php index e1daf47a5..a53c295b2 100644 --- a/tests/Unit/Helper/Filter/JSON/TimezoneFixFilterTest.php +++ b/tests/Unit/Helper/Filter/JSON/TimezoneFixFilterTest.php @@ -25,11 +25,11 @@ public function db() { $hours = sprintf('%+03d00', $offset / 3600); yield ["2024-05-20T10:12:00$hours", "2024-05-20T10:12:00$hours", false]; - yield ["2024-05-20T10:12:00", "2024-05-20T10:12:00$hours", true]; + yield ['2024-05-20T10:12:00', "2024-05-20T10:12:00$hours", true]; yield ["2024-05-20T10:12:00.20$hours", "2024-05-20T10:12:00.20$hours", false]; - yield ["2024-05-20T10:12:00.20", "2024-05-20T10:12:00.20$hours", true]; + yield ['2024-05-20T10:12:00.20', "2024-05-20T10:12:00.20$hours", true]; yield ["2024-05-20T1:12:00$hours", "2024-05-20T1:12:00$hours", false]; - yield ["2024-05-20T1:12:00", "2024-05-20T1:12:00$hours", true]; + yield ['2024-05-20T1:12:00', "2024-05-20T1:12:00$hours", true]; } /** @dataProvider db */ diff --git a/tests/Unit/Helper/HTMLParser/HttpMicrodataParserTest.php b/tests/Unit/Helper/HTMLParser/HttpMicrodataParserTest.php index 958c930c2..2f22f3364 100644 --- a/tests/Unit/Helper/HTMLParser/HttpMicrodataParserTest.php +++ b/tests/Unit/Helper/HTMLParser/HttpMicrodataParserTest.php @@ -86,7 +86,7 @@ public function imageAttributes() { public function testImageVariantsAsAttribute($attribute): void { $l = $this->createStub(IL10N::class); $parser = new HttpMicrodataParser($l); - $content = file_get_contents(__DIR__ . "/res_Microdata/caseImageAttribute.html"); + $content = file_get_contents(__DIR__ . '/res_Microdata/caseImageAttribute.html'); $content = str_replace('%IMAGE_NAME%', $attribute, $content); $this->finishTest($parser, $content, 'caseImage.json'); @@ -99,7 +99,7 @@ public function testImageVariantsAsAttribute($attribute): void { public function testImageVariantsAsContent($attribute): void { $l = $this->createStub(IL10N::class); $parser = new HttpMicrodataParser($l); - $content = file_get_contents(__DIR__ . "/res_Microdata/caseImageContent.html"); + $content = file_get_contents(__DIR__ . '/res_Microdata/caseImageContent.html'); $content = str_replace('%IMAGE_NAME%', $attribute, $content); $this->finishTest($parser, $content, 'caseImage.json'); @@ -118,7 +118,7 @@ public function ingredientVariantAttributes() { public function testIngredientVariants($attribute): void { $l = $this->createStub(IL10N::class); $parser = new HttpMicrodataParser($l); - $content = file_get_contents(__DIR__ . "/res_Microdata/caseIngredient.html"); + $content = file_get_contents(__DIR__ . '/res_Microdata/caseIngredient.html'); $content = str_replace('%INGREDIENT_NAME%', $attribute, $content); $this->finishTest($parser, $content, 'caseIngredient.json'); @@ -138,7 +138,7 @@ public function instructionVariantAttributes() { public function testInstructionVariants($attribute): void { $l = $this->createStub(IL10N::class); $parser = new HttpMicrodataParser($l); - $content = file_get_contents(__DIR__ . "/res_Microdata/caseInstruction.html"); + $content = file_get_contents(__DIR__ . '/res_Microdata/caseInstruction.html'); $content = str_replace('%INSTRUCTION_NAME%', $attribute, $content); $this->finishTest($parser, $content, 'caseInstruction.json'); diff --git a/tests/Unit/Helper/HtmlToDomParserTest.php b/tests/Unit/Helper/HtmlToDomParserTest.php index b21623d99..d3ff48f68 100644 --- a/tests/Unit/Helper/HtmlToDomParserTest.php +++ b/tests/Unit/Helper/HtmlToDomParserTest.php @@ -158,21 +158,21 @@ public function testParsing($successDomParsing, $stateAtEnd, $errors, $numErrors public function dataProviderParsing() { return [ - "failedParsing" => [ + 'failedParsing' => [ false, null, [], [0,0,0], false, ], - "parsingWithoutErrors" => [ + 'parsingWithoutErrors' => [ true, HtmlToDomParser::PARSING_SUCCESS, [], [0,0,0], false, ], - "parsingWithSingleWarning" => [ + 'parsingWithSingleWarning' => [ true, HtmlToDomParser::PARSING_WARNING, [ @@ -181,7 +181,7 @@ public function dataProviderParsing() { [0,0,1], false, ], - "parsingWithSingleError" => [ + 'parsingWithSingleError' => [ true, HtmlToDomParser::PARSING_ERROR, [ @@ -190,7 +190,7 @@ public function dataProviderParsing() { [0,1,0], false, ], - "parsingWithSingleFatal" => [ + 'parsingWithSingleFatal' => [ true, HtmlToDomParser::PARSING_FATAL_ERROR, [ @@ -199,7 +199,7 @@ public function dataProviderParsing() { [1,0,0], false, ], - "parsingWithAllTypes" => [ + 'parsingWithAllTypes' => [ true, HtmlToDomParser::PARSING_FATAL_ERROR, [ @@ -213,7 +213,7 @@ public function dataProviderParsing() { [1,2,3], false, ], - "parsingWithAllTypes" => [ + 'parsingWithAllTypes' => [ true, HtmlToDomParser::PARSING_ERROR, [ @@ -230,7 +230,7 @@ public function dataProviderParsing() { [0,2,3], false, ], - "parsingWithWrongXMLError" => [ + 'parsingWithWrongXMLError' => [ true, HtmlToDomParser::PARSING_SUCCESS, [ @@ -285,8 +285,8 @@ public function testLogging(): void { $this->logger->expects($this->exactly(2)) ->method('warning') ->withConsecutive( - ["libxml: Error %u occurred %n times while parsing %s. First time it occurred in line %u and column %u: The message"], - ["libxml: Error %u occurred %n times while parsing %s. First time it occurred in line %u and column %u: The message"] + ['libxml: Error %u occurred %n times while parsing %s. First time it occurred in line %u and column %u: The message'], + ['libxml: Error %u occurred %n times while parsing %s. First time it occurred in line %u and column %u: The message'] ); $this->logger->expects($this->exactly(0)) ->method('error'); diff --git a/tests/Unit/Helper/TextCleanupHelperTest.php b/tests/Unit/Helper/TextCleanupHelperTest.php index b5f0eae50..eb2891ef6 100644 --- a/tests/Unit/Helper/TextCleanupHelperTest.php +++ b/tests/Unit/Helper/TextCleanupHelperTest.php @@ -20,7 +20,7 @@ public function dpCleanUp() { ["A\r\nfew\nlines with/NL", true, false, 'A few lines with/NL'], ["A/few/words with\nslashes", false, true, "A_few_words with\nslashes"], ["Both/newlines\nand//slashes", true, true, 'Both_newlines and__slashes'], - ["With\tTabs", false, false, "With Tabs"], + ["With\tTabs", false, false, 'With Tabs'], ['With\\backslash\\', false, false, 'With_backslash_'], ['äÜß&', false, false, 'äÜß&'], [null, false, false, ''], diff --git a/tests/Unit/Helper/UserConfigHelperTest.php b/tests/Unit/Helper/UserConfigHelperTest.php index caac97da5..e2f6fa727 100644 --- a/tests/Unit/Helper/UserConfigHelperTest.php +++ b/tests/Unit/Helper/UserConfigHelperTest.php @@ -100,10 +100,10 @@ public function testPrintImage() { ->willReturnOnConsecutiveCalls('0', '1', '0'); $this->config->expects($this->exactly(2))->method('setUserValue') - ->withConsecutive( - [$this->userId, 'cookbook', 'print_image', '1'], - [$this->userId, 'cookbook', 'print_image', '0'] - ); + ->withConsecutive( + [$this->userId, 'cookbook', 'print_image', '1'], + [$this->userId, 'cookbook', 'print_image', '0'] + ); $this->assertFalse($this->dut->getPrintImage()); $this->dut->setPrintImage(true); diff --git a/tests/Unit/Service/JsonServiceTest.php b/tests/Unit/Service/JsonServiceTest.php index 16efbf4af..448dcb919 100644 --- a/tests/Unit/Service/JsonServiceTest.php +++ b/tests/Unit/Service/JsonServiceTest.php @@ -17,17 +17,17 @@ public function setUp(): void { public function testIsSchemaObject() { // Objects must be encoded as arrays in JSON - $testData = "notAnArray"; + $testData = 'notAnArray'; $result = $this->service->isSchemaObject($testData); self::assertFalse($result, 'The object must be an array'); // Objects must have a property @context $testData = [ - "@type" => "Recipe", - "name" => "Schema.org Ontology", - "subjectOf" => [ - "@type" => "Book", - "name" => "The Complete History of Schema.org" + '@type' => 'Recipe', + 'name' => 'Schema.org Ontology', + 'subjectOf' => [ + '@type' => 'Book', + 'name' => 'The Complete History of Schema.org' ] ]; $result = $this->service->isSchemaObject($testData); @@ -37,12 +37,12 @@ public function testIsSchemaObject() { // Context must be in schema.org domain $testData = [ - "@context" => "https://schema.com/", + '@context' => 'https://schema.com/', '@type' => 'Recipe', - "name" => "Schema.org Ontology", - "subjectOf" => [ - "@type" => "Book", - "name" => "The Complete History of Schema.org" + 'name' => 'Schema.org Ontology', + 'subjectOf' => [ + '@type' => 'Book', + 'name' => 'The Complete History of Schema.org' ] ]; $result = $this->service->isSchemaObject($testData); @@ -51,11 +51,11 @@ public function testIsSchemaObject() { // Objects must have a property @type $testData = [ - "@context" => "https://schema.org/", - "name" => "Schema.org Ontology", - "subjectOf" => [ - "@type" => "Book", - "name" => "The Complete History of Schema.org" + '@context' => 'https://schema.org/', + 'name' => 'Schema.org Ontology', + 'subjectOf' => [ + '@type' => 'Book', + 'name' => 'The Complete History of Schema.org' ] ]; $result = $this->service->isSchemaObject($testData); @@ -64,12 +64,12 @@ public function testIsSchemaObject() { // No typecheck will be requested $testData = [ - "@context" => "https://schema.org/", - "@type" => "Thing", - "name" => "Schema.org Ontology", - "subjectOf" => [ - "@type" => "Book", - "name" => "The Complete History of Schema.org" + '@context' => 'https://schema.org/', + '@type' => 'Thing', + 'name' => 'Schema.org Ontology', + 'subjectOf' => [ + '@type' => 'Book', + 'name' => 'The Complete History of Schema.org' ] ]; $result = $this->service->isSchemaObject($testData); @@ -79,12 +79,12 @@ public function testIsSchemaObject() { // Check if type matches $testData = [ - "@context" => "https://schema.org/", - "@type" => "Thing", - "name" => "Schema.org Ontology", - "subjectOf" => [ - "@type" => "Book", - "name" => "The Complete History of Schema.org" + '@context' => 'https://schema.org/', + '@type' => 'Thing', + 'name' => 'Schema.org Ontology', + 'subjectOf' => [ + '@type' => 'Book', + 'name' => 'The Complete History of Schema.org' ] ]; $result = $this->service->isSchemaObject($testData, 'Thing'); @@ -98,12 +98,12 @@ public function testIsSchemaObject() { public function testHasProperty() { // The method isSchemaObject() is tested in another test and assumed as working properly $testData = [ - "@context" => "https://schema.org/", - "@type" => "Thing", - "name" => "Schema.org Ontology", - "subjectOf" => [ - "@type" => "Book", - "name" => "The Complete History of Schema.org" + '@context' => 'https://schema.org/', + '@type' => 'Thing', + 'name' => 'Schema.org Ontology', + 'subjectOf' => [ + '@type' => 'Book', + 'name' => 'The Complete History of Schema.org' ] ]; $result = $this->service->hasProperty($testData, 'name'); diff --git a/tests/bootstrap_helper.php b/tests/bootstrap_helper.php index 46a0f234b..e96532e81 100755 --- a/tests/bootstrap_helper.php +++ b/tests/bootstrap_helper.php @@ -9,7 +9,7 @@ function resetEnvironmentToBackup(string $name = 'main', bool $forceprint = fals print_r($output); echo "Return value: $ret\n"; if ($ret !== 0) { - throw new Exception("Could not reset environment"); + throw new Exception('Could not reset environment'); } } } @@ -29,7 +29,7 @@ function runOCCCommand(array $args, bool $forceprint = false) { print_r($output); echo "Return value: $ret\n"; if ($ret !== 0) { - throw new Exception("Could not run OCC command"); + throw new Exception('Could not run OCC command'); } } }