phpstan, phpcs, phpunit fixes

This commit is contained in:
Dennis Eichhorn 2023-01-27 22:12:09 +01:00
parent 15d381a423
commit d4e46af1c7
12 changed files with 137 additions and 21 deletions

View File

@ -285,8 +285,8 @@
"name": "media_type_rel_dst", "name": "media_type_rel_dst",
"type": "INT", "type": "INT",
"null": false, "null": false,
"foreignTable": "type", "foreignTable": "media_type",
"foreignKey": "type_id" "foreignKey": "media_type_id"
} }
} }
} }

View File

@ -116,7 +116,7 @@ final class Installer extends InstallerAbstract
}; };
$apiApp->dbPool = $app->dbPool; $apiApp->dbPool = $app->dbPool;
$apiApp->unitId = $app->unitId; $apiApp->unitId = $app->unitId;
$apiApp->accountManager = $app->accountManager; $apiApp->accountManager = $app->accountManager;
$apiApp->appSettings = $app->appSettings; $apiApp->appSettings = $app->appSettings;
$apiApp->moduleManager = $app->moduleManager; $apiApp->moduleManager = $app->moduleManager;

View File

@ -378,21 +378,36 @@ final class ApiController extends Controller
return \phpOMS\Utils\Parser\Pdf\PdfParser::pdf2text($path/*, __DIR__ . '/../../../Tools/OCRImageOptimizer/bin/OCRImageOptimizerApp'*/); return \phpOMS\Utils\Parser\Pdf\PdfParser::pdf2text($path/*, __DIR__ . '/../../../Tools/OCRImageOptimizer/bin/OCRImageOptimizerApp'*/);
case 'doc': case 'doc':
case 'docx': case 'docx':
if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) { $include = \realpath(__DIR__ . '/../../../Resources/');
if ($include === false) {
return '';
}
if (!Autoloader::inPaths($include)) {
Autoloader::addPath($include); Autoloader::addPath($include);
} }
return \phpOMS\Utils\Parser\Document\DocumentParser::parseDocument($path, $output); return \phpOMS\Utils\Parser\Document\DocumentParser::parseDocument($path, $output);
case 'ppt': case 'ppt':
case 'pptx': case 'pptx':
if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) { $include = \realpath(__DIR__ . '/../../../Resources/');
if ($include === false) {
return '';
}
if (!Autoloader::inPaths($include)) {
Autoloader::addPath($include); Autoloader::addPath($include);
} }
return \phpOMS\Utils\Parser\Presentation\PresentationParser::parsePresentation($path, $output); return \phpOMS\Utils\Parser\Presentation\PresentationParser::parsePresentation($path, $output);
case 'xls': case 'xls':
case 'xlsx': case 'xlsx':
if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) { $include = \realpath(__DIR__ . '/../../../Resources/');
if ($include === false) {
return '';
}
if (!Autoloader::inPaths($include)) {
Autoloader::addPath($include); Autoloader::addPath($include);
} }
@ -502,6 +517,19 @@ final class ApiController extends Controller
return $media; return $media;
} }
/**
* Api method to create a reference.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiReferenceCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void public function apiReferenceCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{ {
if (!empty($val = $this->validateReferenceCreate($request))) { if (!empty($val = $this->validateReferenceCreate($request))) {
@ -518,6 +546,7 @@ final class ApiController extends Controller
// create relation // create relation
$parentCollectionId = (int) $request->getData('parent'); $parentCollectionId = (int) $request->getData('parent');
if ($parentCollectionId === 0) { if ($parentCollectionId === 0) {
/** @var Collection $parentCollection */
$parentCollection = CollectionMapper::get() $parentCollection = CollectionMapper::get()
->where('virtualPath', (string) ($request->getData('virtualpath') ?? '')) ->where('virtualPath', (string) ($request->getData('virtualpath') ?? ''))
->where('name', (string) ($request->getData('name') ?? '')) ->where('name', (string) ($request->getData('name') ?? ''))
@ -532,7 +561,7 @@ final class ApiController extends Controller
} }
/** /**
* Method to create collection from request. * Method to create a reference from request.
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
@ -542,7 +571,7 @@ final class ApiController extends Controller
*/ */
private function createReferenceFromRequest(RequestAbstract $request) : Reference private function createReferenceFromRequest(RequestAbstract $request) : Reference
{ {
$mediaReference = new Reference(); $mediaReference = new Reference();
$mediaReference->name = (string) $request->getData('name'); $mediaReference->name = (string) $request->getData('name');
$mediaReference->source = new NullMedia((int) $request->getData('source')); $mediaReference->source = new NullMedia((int) $request->getData('source'));
$mediaReference->createdBy = new NullAccount($request->header->account); $mediaReference->createdBy = new NullAccount($request->header->account);
@ -552,7 +581,7 @@ final class ApiController extends Controller
} }
/** /**
* Validate collection create request * Validate reference create request
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *

View File

@ -30,7 +30,7 @@ final class CollectionMapper extends MediaMapper
/** /**
* Has many relation. * Has many relation.
* *
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const HAS_MANY = [ public const HAS_MANY = [
@ -45,7 +45,7 @@ final class CollectionMapper extends MediaMapper
/** /**
* Model to use by the mapper. * Model to use by the mapper.
* *
* @var string * @var class-string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODEL = Collection::class; public const MODEL = Collection::class;

View File

@ -290,9 +290,16 @@ class Media implements \JsonSerializable
return $this->nonce !== null; return $this->nonce !== null;
} }
/**
* Has password defined
*
* @return bool
*
* @since 1.0.0
*/
public function hasPassword() : bool public function hasPassword() : bool
{ {
return !empty($password); return !empty($this->password);
} }
/** /**
@ -463,6 +470,60 @@ class Media implements \JsonSerializable
return $this->types[$id] ?? new NullMediaType(); return $this->types[$id] ?? new NullMediaType();
} }
/**
* Get media type by name
*
* @param string $name Type name
*
* @return MediaType
*
* @since 1.0.0
*/
public function getMediaTypeName(string $name) : MediaType
{
foreach ($this->types as $type) {
if ($type->name === $name) {
return $type;
}
}
return new NullMediaType();
}
/**
* Has media type by id
*
* @param int $id Media type id
*
* @return bool
*
* @since 1.0.0
*/
public function hasMediaTypeId(int $id) : bool
{
return isset($this->types[$id]);
}
/**
* Has media type by name
*
* @param string $name Media type name
*
* @return bool
*
* @since 1.0.0
*/
public function hasMediaTypeName(string $name) : bool
{
foreach ($this->types as $type) {
if ($type->name === $name) {
return true;
}
}
return false;
}
/** /**
* Adding new tag. * Adding new tag.
* *

View File

@ -40,7 +40,7 @@ class MediaContentMapper extends DataMapperFactory
/** /**
* Model to use by the mapper. * Model to use by the mapper.
* *
* @var string * @var class-string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODEL = MediaContent::class; public const MODEL = MediaContent::class;

View File

@ -62,7 +62,7 @@ class MediaMapper extends DataMapperFactory
/** /**
* Belongs to. * Belongs to.
* *
* @var array<string, array{mapper:string, external:string, column?:string, by?:string}> * @var array<string, array{mapper:class-string, external:string, column?:string, by?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const BELONGS_TO = [ public const BELONGS_TO = [
@ -75,7 +75,7 @@ class MediaMapper extends DataMapperFactory
/** /**
* Belongs to. * Belongs to.
* *
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}> * @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const OWNS_ONE = [ public const OWNS_ONE = [
@ -96,7 +96,7 @@ class MediaMapper extends DataMapperFactory
/** /**
* Has many relation. * Has many relation.
* *
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const HAS_MANY = [ public const HAS_MANY = [
@ -117,7 +117,7 @@ class MediaMapper extends DataMapperFactory
/** /**
* Model to use by the mapper. * Model to use by the mapper.
* *
* @var string * @var class-string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODEL = Media::class; public const MODEL = Media::class;

View File

@ -59,7 +59,7 @@ final class MediaTypeL11nMapper extends DataMapperFactory
/** /**
* Model to use by the mapper. * Model to use by the mapper.
* *
* @var string * @var class-string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODEL = BaseStringL11n::class; public const MODEL = BaseStringL11n::class;

View File

@ -41,7 +41,7 @@ final class MediaTypeMapper extends DataMapperFactory
/** /**
* Has many relation. * Has many relation.
* *
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const HAS_MANY = [ public const HAS_MANY = [
@ -57,7 +57,7 @@ final class MediaTypeMapper extends DataMapperFactory
/** /**
* Model to use by the mapper. * Model to use by the mapper.
* *
* @var string * @var class-string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODEL = MediaType::class; public const MODEL = MediaType::class;

View File

@ -115,6 +115,10 @@ class UploadFile
$fCounter = -1; $fCounter = -1;
foreach ($files as $key => $f) { foreach ($files as $key => $f) {
if (!isset($f['name'], $f['tmp_name'], $f['size'])) {
return [];
}
++$fCounter; ++$fCounter;
$path = $this->outputDir; $path = $this->outputDir;

View File

@ -0,0 +1,16 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Media
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
return ['Media' => [
]];

View File

@ -186,7 +186,13 @@ trait ApiControllerMediaTrait
{ {
self::assertEquals( self::assertEquals(
[], [],
$this->module->uploadFiles(['test'], ['test'], ['test'], 1, '/test', '', null, '', '', 99) $this->module->uploadFiles(
names: ['test'],
fileNames: ['test'],
files: ['test'],
account: 1,
basePath: '/test',
)
); );
} }