fix phpstan/phpcs

This commit is contained in:
Dennis Eichhorn 2021-06-26 14:38:08 +02:00
parent 5e016b028f
commit ba52dcaa8b
10 changed files with 69 additions and 53 deletions

View File

@ -42,7 +42,7 @@ final class Installer extends InstallerAbstract
* Install data from providing modules. * Install data from providing modules.
* *
* @param ApplicationAbstract $app Application * @param ApplicationAbstract $app Application
* @param array $data Module info * @param array $data Additional data
* *
* @return array * @return array
* *
@ -116,7 +116,7 @@ final class Installer extends InstallerAbstract
$path = '/Modules/Media/Files' . ($data['virtualPath'] ?? '') . '/' . ($data['name'] ?? ''); $path = '/Modules/Media/Files' . ($data['virtualPath'] ?? '') . '/' . ($data['name'] ?? '');
} else { } else {
$dirPath = $data['path'] . '/' . ($data['name'] ?? ''); $dirPath = $data['path'] . '/' . ($data['name'] ?? '');
$path = $data['path'] ?? '/Modules/Media/Files' . '/' . ($data['name'] ?? ''); $path = $data['path'] ?? '/Modules/Media/Files/' . ($data['name'] ?? '');
} }
$collection = new Collection(); $collection = new Collection();
@ -193,7 +193,7 @@ final class Installer extends InstallerAbstract
$media = new Media(); $media = new Media();
$media->setPath(ApiController::normalizeDbPath($data['path']) . '/' . $uFile['filename']); $media->setPath(ApiController::normalizeDbPath($data['path']) . '/' . $uFile['filename']);
$media->name = $uFile['name']; $media->name = $uFile['filename'];
$media->size = $uFile['size']; $media->size = $uFile['size'];
$media->createdBy = new NullAccount((int) $data['user'] ?? 1); $media->createdBy = new NullAccount((int) $data['user'] ?? 1);
$media->extension = $uFile['extension']; $media->extension = $uFile['extension'];

View File

@ -172,6 +172,17 @@ final class ApiController extends Controller
return $this->createDbEntries($status, $account, $virtualPath, $type); return $this->createDbEntries($status, $account, $virtualPath, $type);
} }
/**
* Uploads a file to a destination
*
* @param array $files Files to upload
* @param string $name Name of the file (only if a single file is provided)
* @param string $path Upload path
*
* @return array
*
* @since 1.0.0
*/
public static function uploadFilesToDestination( public static function uploadFilesToDestination(
array $files, array $files,
string $name = '', string $name = '',
@ -266,7 +277,7 @@ final class ApiController extends Controller
$media = new Media(); $media = new Media();
$media->setPath(self::normalizeDbPath($status['path']) . '/' . $status['filename']); $media->setPath(self::normalizeDbPath($status['path']) . '/' . $status['filename']);
$media->name = $status['name']; $media->name = empty($status['name']) ? $status['filename'] : $status['name'];
$media->size = $status['size']; $media->size = $status['size'];
$media->createdBy = new NullAccount($account); $media->createdBy = new NullAccount($account);
$media->extension = $status['extension']; $media->extension = $status['extension'];
@ -579,7 +590,7 @@ final class ApiController extends Controller
public function apiMediaExport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void public function apiMediaExport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{ {
/** @var Media $media */ /** @var Media $media */
$media = MediaMapper::get((int) $request->getData('id')); $media = MediaMapper::get((int) $request->getData('id'));
$view = $this->createView($media, $request, $response); $view = $this->createView($media, $request, $response);
$this->setMediaResponseHeader($view, $media, $request, $response); $this->setMediaResponseHeader($view, $media, $request, $response);

View File

@ -88,6 +88,15 @@ class Collection extends Media implements \Iterator
return $this->sources; return $this->sources;
} }
/**
* Get media element by its name.
*
* @param string $name Name of the media element
*
* @return Media
*
* @since 1.0.0
*/
public function getSourceByName(string $name) : Media public function getSourceByName(string $name) : Media
{ {
foreach ($this->sources as $source) { foreach ($this->sources as $source) {

View File

@ -100,11 +100,11 @@ final class CollectionMapper extends MediaMapper
{ {
$depth = 3; $depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.media_virtual', '=', $virtualPath); $query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath);
$query->where(self::$table . '_' . $depth . '.media_collection', '=', 1); $query->where(self::$table . '_d' . $depth . '.media_collection', '=', 1);
if ($hidden === false) { if ($hidden === false) {
$query->andWhere(self::$table . '_' . $depth . '.media_hidden', '=', (int) $hidden); $query->andWhere(self::$table . '_d' . $depth . '.media_hidden', '=', (int) $hidden);
} }
return self::getAllByQuery($query, RelationType::ALL, $depth); return self::getAllByQuery($query, RelationType::ALL, $depth);

View File

@ -141,10 +141,10 @@ class MediaMapper extends DataMapperAbstract
{ {
$depth = 3; $depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.media_virtual', '=', $virtualPath); $query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath);
if ($hidden === false) { if ($hidden === false) {
$query->andWhere(self::$table . '_' . $depth . '.media_hidden', '=', (int) $hidden); $query->andWhere(self::$table . '_d' . $depth . '.media_hidden', '=', (int) $hidden);
} }
return self::getAllByQuery($query, RelationType::ALL, $depth); return self::getAllByQuery($query, RelationType::ALL, $depth);
@ -166,8 +166,8 @@ class MediaMapper extends DataMapperAbstract
$depth = 3; $depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table. '_' . $depth . '.media_virtual', '=', $virtualPath) $query->where(self::$table. '_d' . $depth . '.media_virtual', '=', $virtualPath)
->andWhere(self::$table. '_' . $depth . '.media_name', '=', $name); ->andWhere(self::$table. '_d' . $depth . '.media_name', '=', $name);
$objs = self::getAllByQuery($query, RelationType::ALL, $depth); $objs = self::getAllByQuery($query, RelationType::ALL, $depth);

View File

@ -107,6 +107,8 @@ class UploadFile
$files = [$files]; $files = [$files];
} }
$fileCount = \count($files);
if (!$absolute && \count($files) > 1) { if (!$absolute && \count($files) > 1) {
$this->outputDir = $this->findOutputDir(); $this->outputDir = $this->findOutputDir();
} }
@ -158,7 +160,7 @@ class UploadFile
$result[$key]['filename'] = $name; $result[$key]['filename'] = $name;
} }
if (empty($name) || \is_file($path . '/' . $name)) { if (!$this->preserveFileName || $fileCount !== 1 || empty($name) || \is_file($path . '/' . $name)) {
try { try {
$name = $this->createFileName($path, $f['tmp_name'], $extension); $name = $this->createFileName($path, $f['tmp_name'], $extension);
$result[$key]['filename'] = $name; $result[$key]['filename'] = $name;
@ -170,6 +172,8 @@ class UploadFile
} }
} }
$result[$key]['name'] = empty($name) ? $result[$key]['filename'] : $name;
if (!\is_dir($path)) { if (!\is_dir($path)) {
$created = Directory::create($path, 0755, true); $created = Directory::create($path, 0755, true);

View File

@ -39,14 +39,6 @@ class ElementView extends MediaView
*/ */
protected Media $media; protected Media $media;
/**
* {@inheritdoc}
*/
public function __construct(L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response)
{
parent::__construct($l11n, $request, $response);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -17,45 +17,45 @@ Autoloader::addPath(__DIR__ . '/../../../../../../Resources/');
<div class="tab-content"> <div class="tab-content">
<input type="radio" id="media-c-tab-1" name="tabular-1" checked> <input type="radio" id="media-c-tab-1" name="tabular-1" checked>
<div class="tab"> <div class="tab">
<iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe> <iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
</div> </div>
<input type="radio" id="media-c-tab-2" name="tabular-1" checked> <input type="radio" id="media-c-tab-2" name="tabular-1" checked>
<div class="tab"> <div class="tab">
<?php <?php
$reader = IOFactory::createReaderforFile(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath()); $reader = IOFactory::createReaderforFile(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
$reader->setReadDataOnly(true); $reader->setReadDataOnly(true);
$spreadsheet = $reader->load(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath()); $spreadsheet = $reader->load(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
$writer = new Csv($spreadsheet); $writer = new Csv($spreadsheet);
$writer->setDelimiter(';'); $writer->setDelimiter(';');
$writer->setEnclosure('"'); $writer->setEnclosure('"');
$writer->setLineEnding("\n"); $writer->setLineEnding("\n");
$writer->setUseBOM(true); $writer->setUseBOM(true);
\ob_start(); \ob_start();
$writer->save('php://output'); $writer->save('php://output');
$data = \ob_get_clean(); $data = \ob_get_clean();
$csv = \explode("\n", \trim($data, "\n")); $csv = \explode("\n", \trim($data, "\n"));
?> ?>
<table class="default"> <table class="default">
<?php <?php
foreach ($csv as $line) { foreach ($csv as $line) {
$lineCsv = \str_getcsv($line, ';', '"'); $lineCsv = \str_getcsv($line, ';', '"');
if ($lineCsv === null) { if ($lineCsv === null) {
break; break;
} }
echo '<tr>'; echo '<tr>';
foreach ($lineCsv as $cell) { foreach ($lineCsv as $cell) {
if ($cell === null) { if ($cell === null) {
break; break;
} }
echo '<td>' . \htmlspecialchars($cell); echo '<td>' . \htmlspecialchars($cell);
} }
} }
?> ?>
</table> </table>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,6 +5,6 @@ use phpOMS\Uri\UriFactory;
?> ?>
<section id="mediaFile" class="portlet"> <section id="mediaFile" class="portlet">
<div class="portlet-body"> <div class="portlet-body">
<iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe> <iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
</div> </div>
</section> </section>

View File

@ -9,7 +9,7 @@
], ],
"require-dev": { "require-dev": {
"phpunit/phpunit": ">=9.4", "phpunit/phpunit": ">=9.4",
"friendsofphp/php-cs-fixer": ">=2.18", "friendsofphp/php-cs-fixer": ">=3.0",
"squizlabs/php_codesniffer": ">=3.5", "squizlabs/php_codesniffer": ">=3.5",
"phpmd/phpmd": ">=2.9", "phpmd/phpmd": ">=2.9",
"phpstan/phpstan": ">=0.12.58", "phpstan/phpstan": ">=0.12.58",