From 9c86db62fc2b078a39278164c94804599b6cc914 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 18 Oct 2020 20:55:17 +0200 Subject: [PATCH] rename l11ntag to tagl11n --- Controller/ApiController.php | 18 +++++++++--------- Controller/BackendController.php | 4 ++-- Models/{NullL11nTag.php => NullTagL11n.php} | 2 +- Models/Tag.php | 12 ++++++------ Models/{L11nTag.php => TagL11n.php} | 7 ++++--- .../{L11nTagMapper.php => TagL11nMapper.php} | 2 +- Models/TagMapper.php | 2 +- ...TagMapperTest.php => TagL11nMapperTest.php} | 14 +++++++------- .../{L11nTagTest.php => TagL11nTest.php} | 18 +++++++++--------- tests/Models/TagTest.php | 6 +++--- 10 files changed, 43 insertions(+), 42 deletions(-) rename Models/{NullL11nTag.php => NullTagL11n.php} (91%) rename Models/{L11nTag.php => TagL11n.php} (92%) rename Models/{L11nTagMapper.php => TagL11nMapper.php} (97%) rename tests/Models/{L11nTagMapperTest.php => TagL11nMapperTest.php} (78%) rename tests/Models/{L11nTagTest.php => TagL11nTest.php} (83%) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 1a92f3d..0d21c57 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Modules\Tag\Controller; -use Modules\Tag\Models\L11nTag; -use Modules\Tag\Models\L11nTagMapper; +use Modules\Tag\Models\TagL11n; +use Modules\Tag\Models\TagL11nMapper; use Modules\Tag\Models\Tag; use Modules\Tag\Models\TagMapper; use phpOMS\Message\Http\HttpRequest; @@ -135,8 +135,8 @@ final class ApiController extends Controller $l11nRequest->setData('color', $request->getData('color')); $l11nRequest->setData('language', $request->getData('language')); - $l11nTag = $this->createL11nTagFromRequest($l11nRequest); - $this->createModel($request->getHeader()->getAccount(), $l11nTag, L11nTagMapper::class, 'tag_l11n', $request->getOrigin()); + $l11nTag = $this->createTagL11nFromRequest($l11nRequest); + $this->createModel($request->getHeader()->getAccount(), $l11nTag, TagL11nMapper::class, 'tag_l11n', $request->getOrigin()); $tag->setTitle($l11nTag); @@ -186,8 +186,8 @@ final class ApiController extends Controller return; } - $l11nTag = $this->createL11nTagFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $l11nTag, L11nTagMapper::class, 'tag_l11n', $request->getOrigin()); + $l11nTag = $this->createTagL11nFromRequest($request); + $this->createModel($request->getHeader()->getAccount(), $l11nTag, TagL11nMapper::class, 'tag_l11n', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Tag localization successfully created', $l11nTag); } @@ -214,13 +214,13 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return L11nTag + * @return TagL11n * * @since 1.0.0 */ - private function createL11nTagFromRequest(RequestAbstract $request) : L11nTag + private function createTagL11nFromRequest(RequestAbstract $request) : TagL11n { - $l11nTag = new L11nTag(); + $l11nTag = new TagL11n(); $l11nTag->setTag((int) ($request->getData('tag') ?? 0)); $l11nTag->setLanguage((string) ( $request->getData('language') ?? $request->getHeader()->getL11n()->getLanguage() diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e307f48..896e8b5 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Tag\Controller; -use Modules\Tag\Models\L11nTagMapper; +use Modules\Tag\Models\TagL11nMapper; use Modules\Tag\Models\TagMapper; use phpOMS\Contract\RenderableInterface; use phpOMS\Message\RequestAbstract; @@ -113,7 +113,7 @@ final class BackendController extends Controller $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response)); $view->addData('tag', $tag); - $l11n = L11nTagMapper::withConditional('tag', $tag->getId())::getAll(); + $l11n = TagL11nMapper::withConditional('tag', $tag->getId())::getAll(); $view->addData('l11n', $l11n); return $view; diff --git a/Models/NullL11nTag.php b/Models/NullTagL11n.php similarity index 91% rename from Models/NullL11nTag.php rename to Models/NullTagL11n.php index a9413a4..539de4c 100644 --- a/Models/NullL11nTag.php +++ b/Models/NullTagL11n.php @@ -22,6 +22,6 @@ namespace Modules\Tag\Models; * @link https://orange-management.org * @since 1.0.0 */ -final class NullL11nTag extends Tag +final class NullTagL11n extends TagL11n { } diff --git a/Models/Tag.php b/Models/Tag.php index ff27f51..eed0ee3 100755 --- a/Models/Tag.php +++ b/Models/Tag.php @@ -40,7 +40,7 @@ class Tag implements \JsonSerializable, ArrayableInterface /** * Title. * - * @var string|L11nTag + * @var string|TagL11n * @since 1.0.0 */ private $title = ''; @@ -166,13 +166,13 @@ class Tag implements \JsonSerializable, ArrayableInterface */ public function getTitle() : string { - return $this->title instanceof L11nTag ? $this->title->getTitle() : $this->title; + return $this->title instanceof TagL11n ? $this->title->getTitle() : $this->title; } /** * Set title * - * @param string|L11nTag $title Tag article title + * @param string|TagL11n $title Tag article title * * @return void * @@ -180,12 +180,12 @@ class Tag implements \JsonSerializable, ArrayableInterface */ public function setTitle($title, string $lang = ISO639x1Enum::_EN) : void { - if ($title instanceof L11nTag) { + if ($title instanceof TagL11n) { $this->title = $title; - } elseif ($this->title instanceof L11nTag && \is_string($title)) { + } elseif ($this->title instanceof TagL11n && \is_string($title)) { $this->title->setTitle($title); } elseif (\is_string($title)) { - $this->title = new L11nTag(); + $this->title = new TagL11n(); $this->title->setTitle($title); $this->title->setLanguage($lang); } diff --git a/Models/L11nTag.php b/Models/TagL11n.php similarity index 92% rename from Models/L11nTag.php rename to Models/TagL11n.php index aa6c1bf..d5c55cc 100755 --- a/Models/L11nTag.php +++ b/Models/TagL11n.php @@ -25,7 +25,7 @@ use phpOMS\Localization\ISO639x1Enum; * @link https://orange-management.org * @since 1.0.0 */ -class L11nTag implements \JsonSerializable, ArrayableInterface +class TagL11n implements \JsonSerializable, ArrayableInterface { /** * Article ID. @@ -66,9 +66,10 @@ class L11nTag implements \JsonSerializable, ArrayableInterface * * @since 1.0.0 */ - public function __construct(string $title = '') + public function __construct(string $title = '', string $language = ISO639x1Enum::_EN) { - $this->title = $title; + $this->title = $title; + $this->language = $language; } /** diff --git a/Models/L11nTagMapper.php b/Models/TagL11nMapper.php similarity index 97% rename from Models/L11nTagMapper.php rename to Models/TagL11nMapper.php index c17c8d9..9256a62 100755 --- a/Models/L11nTagMapper.php +++ b/Models/TagL11nMapper.php @@ -27,7 +27,7 @@ use phpOMS\Localization\Defaults\LanguageMapper; * * @todo Do I really want to create a relation to the language mapper? It's not really needed right? */ -final class L11nTagMapper extends DataMapperAbstract +final class TagL11nMapper extends DataMapperAbstract { /** * Columns. diff --git a/Models/TagMapper.php b/Models/TagMapper.php index 6106710..2ff51f5 100755 --- a/Models/TagMapper.php +++ b/Models/TagMapper.php @@ -52,7 +52,7 @@ final class TagMapper extends DataMapperAbstract */ protected static array $hasMany = [ 'title' => [ - 'mapper' => L11nTagMapper::class, + 'mapper' => TagL11nMapper::class, 'table' => 'tag_l11n', 'external' => 'tag_l11n_tag', 'column' => 'title', diff --git a/tests/Models/L11nTagMapperTest.php b/tests/Models/TagL11nMapperTest.php similarity index 78% rename from tests/Models/L11nTagMapperTest.php rename to tests/Models/TagL11nMapperTest.php index 3cd724b..769567e 100644 --- a/tests/Models/L11nTagMapperTest.php +++ b/tests/Models/TagL11nMapperTest.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Modules\Tag\tests\Models; -use Modules\Tag\Models\L11nTag; -use Modules\Tag\Models\L11nTagMapper; +use Modules\Tag\Models\TagL11n; +use Modules\Tag\Models\TagL11nMapper; use Modules\Tag\Models\Tag; use Modules\Tag\Models\TagMapper; use Modules\Tag\Models\TagType; @@ -24,10 +24,10 @@ use phpOMS\Localization\ISO639x1Enum; /** * @internal */ -class L11nTagMapperTest extends \PHPUnit\Framework\TestCase +class TagL11nMapperTest extends \PHPUnit\Framework\TestCase { /** - * @covers Modules\Tag\Models\L11nTagMapper + * @covers Modules\Tag\Models\TagL11nMapper * @group module */ public function testCR() : void @@ -40,16 +40,16 @@ class L11nTagMapperTest extends \PHPUnit\Framework\TestCase self::assertGreaterThan(0, $tag->getId()); self::assertEquals($id, $tag->getId()); - $l11n = new L11nTag(); + $l11n = new TagL11n(); $l11n->setTitle('TestTitle'); $l11n->setLanguage(ISO639x1Enum::_EN); $l11n->setTag($id); - $id = L11nTagMapper::create($l11n); + $id = TagL11nMapper::create($l11n); self::assertGreaterThan(0, $l11n->getId()); self::assertEquals($id, $l11n->getId()); - $l11nR = L11nTagMapper::get($l11n->getId()); + $l11nR = TagL11nMapper::get($l11n->getId()); self::assertEquals($l11n->getTitle(), $l11nR->getTitle()); self::assertEquals($l11n->getLanguage(), $l11nR->getLanguage()); } diff --git a/tests/Models/L11nTagTest.php b/tests/Models/TagL11nTest.php similarity index 83% rename from tests/Models/L11nTagTest.php rename to tests/Models/TagL11nTest.php index a62f41d..b4aae78 100644 --- a/tests/Models/L11nTagTest.php +++ b/tests/Models/TagL11nTest.php @@ -14,23 +14,23 @@ declare(strict_types=1); namespace Modules\Tag\tests\Models; -use Modules\Tag\Models\L11nTag; +use Modules\Tag\Models\TagL11n; use phpOMS\Localization\ISO639x1Enum; /** * @internal */ -class L11nTagTest extends \PHPUnit\Framework\TestCase +class TagL11nTest extends \PHPUnit\Framework\TestCase { - private L11nTag $l11n; + private TagL11n $l11n; protected function setUp() : void { - $this->l11n = new L11nTag(); + $this->l11n = new TagL11n(); } /** - * @covers Modules\Tag\Models\L11nTag + * @covers Modules\Tag\Models\TagL11n * @group module */ public function testDefault() : void @@ -42,7 +42,7 @@ class L11nTagTest extends \PHPUnit\Framework\TestCase } /** - * @covers Modules\Tag\Models\L11nTag + * @covers Modules\Tag\Models\TagL11n * @group module */ public function testTagInputOutput() : void @@ -52,7 +52,7 @@ class L11nTagTest extends \PHPUnit\Framework\TestCase } /** - * @covers Modules\Tag\Models\L11nTag + * @covers Modules\Tag\Models\TagL11n * @group module */ public function testLanguageInputOutput() : void @@ -62,7 +62,7 @@ class L11nTagTest extends \PHPUnit\Framework\TestCase } /** - * @covers Modules\Tag\Models\L11nTag + * @covers Modules\Tag\Models\TagL11n * @group module */ public function testTitleInputOutput() : void @@ -72,7 +72,7 @@ class L11nTagTest extends \PHPUnit\Framework\TestCase } /** - * @covers Modules\Tag\Models\L11nTag + * @covers Modules\Tag\Models\TagL11n * @group module */ public function testSerialize() : void diff --git a/tests/Models/TagTest.php b/tests/Models/TagTest.php index c8da7b2..b4c3da6 100644 --- a/tests/Models/TagTest.php +++ b/tests/Models/TagTest.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\Tag\tests\Models; use Modules\Admin\Models\NullAccount; -use Modules\Tag\Models\L11nTag; +use Modules\Tag\Models\TagL11n; use Modules\Tag\Models\Tag; use Modules\Tag\Models\TagType; @@ -53,7 +53,7 @@ class TagTest extends \PHPUnit\Framework\TestCase $this->tag->setTitle('Test'); self::assertEquals('Test', $this->tag->getTitle()); - $this->tag->setTitle(new L11nTag('Test2')); + $this->tag->setTitle(new TagL11n('Test2')); self::assertEquals('Test2', $this->tag->getTitle()); $this->tag->setTitle('Test3'); @@ -96,7 +96,7 @@ class TagTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->tag->setTitle($t = new L11nTag('Test')); + $this->tag->setTitle($t = new TagL11n('Test')); $this->tag->setOwner($a = new NullAccount(2)); $this->tag->setColor('ffffffff'); $this->tag->setType(TagType::SHARED);