cs fixes, bug fixes, code coverage

This commit is contained in:
Dennis Eichhorn 2021-11-16 00:05:43 +01:00
parent e0d4930d4a
commit bc5a307734
11 changed files with 627 additions and 12 deletions

View File

@ -0,0 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Web\Backend
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
return [
[
'name' => 'phone',
'l11n' => [
[
'lang' => 'en',
'title' => 'Phone',
],
],
],
[
'name' => 'email',
'l11n' => [
[
'lang' => 'en',
'title' => 'Email',
],
],
],
[
'name' => 'meeting',
'l11n' => [
[
'lang' => 'en',
'title' => 'Meeting',
],
],
],
];

View File

@ -1,4 +1,53 @@
{
"editor_doc_type": {
"name": "editor_doc_type",
"fields": {
"editor_doc_type_id": {
"name": "editor_doc_type_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"editor_doc_type_name": {
"name": "editor_doc_type_name",
"type": "VARCHAR(255)",
"null": false
}
}
},
"editor_doc_type_l11n": {
"name": "editor_doc_type_l11n",
"fields": {
"editor_doc_type_l11n_id": {
"name": "editor_doc_type_l11n_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"editor_doc_type_l11n_title": {
"name": "editor_doc_type_l11n_title",
"type": "VARCHAR(255)",
"null": false
},
"editor_doc_type_l11n_type": {
"name": "editor_doc_type_l11n_type",
"type": "INT",
"null": false,
"foreignTable": "editor_doc_type",
"foreignKey": "editor_doc_type_id"
},
"editor_doc_type_l11n_language": {
"name": "editor_doc_type_l11n_language",
"type": "VARCHAR(2)",
"default": null,
"null": true,
"foreignTable": "language",
"foreignKey": "language_639_1"
}
}
},
"editor_doc": {
"name": "editor_doc",
"fields": {

View File

@ -14,7 +14,16 @@ declare(strict_types=1);
namespace Modules\Editor\Admin;
use Modules\Editor\Models\EditorDocType;
use Modules\Editor\Models\EditorDocTypeL11n;
use Modules\Editor\Models\EditorDocTypeL11nMapper;
use Modules\Editor\Models\EditorDocTypeMapper;
use phpOMS\Application\ApplicationAbstract;
use phpOMS\Config\SettingsInterface;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\InstallerAbstract;
use phpOMS\Module\ModuleInfo;
use phpOMS\System\File\PathException;
/**
* Installer class.
@ -33,4 +42,97 @@ final class Installer extends InstallerAbstract
* @since 1.0.0
*/
public const PATH = __DIR__;
/**
* {@inheritdoc}
*/
public static function install(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void
{
parent::install($dbPool, $info, $cfgHandler);
$types = include __DIR__ . '/Install/Types/types.php';
foreach ($types as $type) {
self::createType($dbPool, $type);
}
}
/**
* Install data from providing modules.
*
* The data can be either directories which should be created or files which should be "uploaded"
*
* @param ApplicationAbstract $app Application
* @param array $data Additional data
*
* @return array
*
* @throws PathException
* @throws \Exception
*
* @since 1.0.0
*/
public static function installExternal(ApplicationAbstract $app, array $data) : array
{
try {
$app->dbPool->get()->con->query('select 1 from `editor_doc`');
} catch (\Exception $e) {
return []; // @codeCoverageIgnore
}
if (!\is_file($data['path'] ?? '')) {
throw new PathException($data['path'] ?? '');
}
$editorFile = \file_get_contents($data['path'] ?? '');
if ($editorFile === false) {
throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore
}
$editorData = \json_decode($editorFile, true) ?? [];
if ($editorData === false) {
throw new \Exception(); // @codeCoverageIgnore
}
$result = [
'type' => [],
];
foreach ($editorData as $editor) {
switch ($editor['type']) {
case 'type':
$result['type'][] = self::createType($app->dbPool, $editor);
break;
default:
}
}
return $result;
}
/**
* Create type.
*
* @param DatabasePool $dbPool Database instance
* @param array $data Type info
*
* @return EditorDocType
*
* @since 1.0.0
*/
private static function createType(DatabasePool $dbPool, array $data) : EditorDocType
{
$type = new EditorDocType();
$type->name = $data['name'] ?? '';
$id = EditorDocTypeMapper::create($type);
foreach ($data['l11n'] as $l11n) {
$l11n = new EditorDocTypeL11n($l11n['title'], $l11n['lang']);
$l11n->type = $id;
EditorDocTypeL11nMapper::create($l11n);
}
return $type;
}
}

View File

@ -12,9 +12,7 @@ If you have a good idea for improvement feel free to create a new issue with all
### Issues
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the `Project.md` file in the `Docs` repository.
The issue information can be used to provide additional information such as priority, difficulty and type. For your first issue try to find a issue marked `[d:first]` or `[d:beginner]`.
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code marked with `@todo` or in the [PROJECT.md](https://github.com/Orange-Management/Docs/blob/master/Project/PROJECT.md) file.
### Code Style

View File

@ -62,6 +62,14 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface
*/
public string $plain = '';
/**
* Type.
*
* @var null|int|EditorDoc
* @since 1.0.0
*/
public null | int | EditorDocType $type = null;
/**
* Doc path for organizing.
*

View File

@ -37,14 +37,15 @@ final class EditorDocMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static array $columns = [
'editor_doc_id' => ['name' => 'editor_doc_id', 'type' => 'int', 'internal' => 'id'],
'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'editor_doc_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'],
'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'],
'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],
'editor_doc_virtual' => ['name' => 'editor_doc_virtual', 'type' => 'string', 'internal' => 'virtualPath'],
'editor_doc_created_at' => ['name' => 'editor_doc_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
'editor_doc_visible' => ['name' => 'editor_doc_visible', 'type' => 'bool', 'internal' => 'isVisible'],
'editor_doc_id' => ['name' => 'editor_doc_id', 'type' => 'int', 'internal' => 'id'],
'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'editor_doc_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'],
'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'],
'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],
'editor_doc_type' => ['name' => 'editor_doc_type', 'type' => 'int', 'internal' => 'type'],
'editor_doc_virtual' => ['name' => 'editor_doc_virtual', 'type' => 'string', 'internal' => 'virtualPath'],
'editor_doc_created_at' => ['name' => 'editor_doc_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
'editor_doc_visible' => ['name' => 'editor_doc_visible', 'type' => 'bool', 'internal' => 'isVisible'],
];
/**
@ -60,6 +61,19 @@ final class EditorDocMapper extends DataMapperAbstract
],
];
/**
* Belongs to.
*
* @var array<string, array{mapper:string, external:string}>
* @since 1.0.0
*/
protected static array $ownsOne = [
'type' => [
'mapper' => EdutirDocTypeMapper::class,
'external' => 'editor_doc_type',
],
];
/**
* Has many relation.
*

132
Models/EditorDocType.php Normal file
View File

@ -0,0 +1,132 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
/**
* EditorDoc type class.
*
* @package Modules\Editor\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class EditorDocType implements \JsonSerializable, ArrayableInterface
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Name.
*
* Name used for additional identification, doesn't have to be unique.
*
* @var string
* @since 1.0.0
*/
public string $name = '';
/**
* Title.
*
* @var string|EditorDocTypeL11n
* @since 1.0.0
*/
protected $title;
/**
* Constructor.
*
* @param string $name Name
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->setL11n($name);
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
*/
public function getL11n() : string
{
return $this->title instanceof EditorDocTypeL11n ? $this->title->title : $this->title;
}
/**
* Set title
*
* @param string|EditorDocTypeL11n $title EditorDoc article title
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setL11n(string | EditorDocTypeL11n $title, string $lang = ISO639x1Enum::_EN) : void
{
if ($title instanceof EditorDocTypeL11n) {
$this->title = $title;
} elseif (isset($this->title) && $this->title instanceof EditorDocTypeL11n) {
$this->title->title = $title;
} else {
$this->title = new EditorDocTypeL11n();
$this->title->title = $title;
$this->title->setLanguage($lang);
}
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'name' => $this->name,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->toArray();
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
/**
* Editor type l11n class.
*
* @package Modules\Editor\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class EditorDocTypeL11n implements \JsonSerializable, ArrayableInterface
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Type ID.
*
* @var int
* @since 1.0.0
*/
public int $type = 0;
/**
* Language.
*
* @var string
* @since 1.0.0
*/
protected string $language = ISO639x1Enum::_EN;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
public string $title = '';
/**
* Constructor.
*
* @param string $title Title
*
* @since 1.0.0
*/
public function __construct(string $title = '', string $language = ISO639x1Enum::_EN)
{
$this->title = $title;
$this->language = $language;
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* Get language
*
* @return string
*
* @since 1.0.0
*/
public function getLanguage() : string
{
return $this->language;
}
/**
* Set language
*
* @param string $language Language
*
* @return void
*
* @since 1.0.0
*/
public function setLanguage(string $language) : void
{
$this->language = $language;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'type' => $this->type,
'language' => $this->language,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->toArray();
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Editor type l11n mapper class.
*
* @package Modules\Editor\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class EditorDocTypeL11nMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0
*/
protected static array $columns = [
'editor_doc_type_l11n_id' => ['name' => 'editor_doc_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
'editor_doc_type_l11n_title' => ['name' => 'editor_doc_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'editor_doc_type_l11n_type' => ['name' => 'editor_doc_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
'editor_doc_type_l11n_language' => ['name' => 'editor_doc_type_l11n_language', 'type' => 'string', 'internal' => 'language'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static string $table = 'editor_doc_type_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'editor_doc_type_l11n_id';
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Editor type mapper class.
*
* @package Modules\Editor\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class EditorDocTypeMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0
*/
protected static array $columns = [
'editor_doc_type_id' => ['name' => 'editor_doc_type_id', 'type' => 'int', 'internal' => 'id'],
'editor_doc_type_name' => ['name' => 'editor_doc_type_name', 'type' => 'string', 'internal' => 'name'],
];
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
protected static array $hasMany = [
'title' => [
'mapper' => EditorDocTypeL11nMapper::class,
'table' => 'editor_doc_type_l11n',
'self' => 'editor_doc_type_l11n_type',
'column' => 'title',
'conditional' => true,
'external' => null,
],
];
/**
* Model to use by the mapper.
*
* @var string
* @since 1.0.0
*/
protected static string $model = EditorDocType::class;
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static string $table = 'editor_doc_type';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'editor_doc_type_id';
}

View File

@ -17,7 +17,6 @@ namespace Modules\Editor\tests\Models;
use Modules\Admin\Models\NullAccount;
use Modules\Editor\Models\EditorDoc;
use Modules\Editor\Models\EditorDocMapper;
use phpOMS\Utils\RnG\Text;
/**
* @internal