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

View File

@ -172,6 +172,17 @@ final class ApiController extends Controller
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(
array $files,
string $name = '',
@ -266,7 +277,7 @@ final class ApiController extends Controller
$media = new Media();
$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->createdBy = new NullAccount($account);
$media->extension = $status['extension'];
@ -579,7 +590,7 @@ final class ApiController extends Controller
public function apiMediaExport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
/** @var Media $media */
$media = MediaMapper::get((int) $request->getData('id'));
$media = MediaMapper::get((int) $request->getData('id'));
$view = $this->createView($media, $request, $response);
$this->setMediaResponseHeader($view, $media, $request, $response);

View File

@ -88,6 +88,15 @@ class Collection extends Media implements \Iterator
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
{
foreach ($this->sources as $source) {

View File

@ -100,11 +100,11 @@ final class CollectionMapper extends MediaMapper
{
$depth = 3;
$query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.media_virtual', '=', $virtualPath);
$query->where(self::$table . '_' . $depth . '.media_collection', '=', 1);
$query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath);
$query->where(self::$table . '_d' . $depth . '.media_collection', '=', 1);
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);

View File

@ -141,10 +141,10 @@ class MediaMapper extends DataMapperAbstract
{
$depth = 3;
$query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.media_virtual', '=', $virtualPath);
$query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath);
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);
@ -166,8 +166,8 @@ class MediaMapper extends DataMapperAbstract
$depth = 3;
$query = self::getQuery();
$query->where(self::$table. '_' . $depth . '.media_virtual', '=', $virtualPath)
->andWhere(self::$table. '_' . $depth . '.media_name', '=', $name);
$query->where(self::$table. '_d' . $depth . '.media_virtual', '=', $virtualPath)
->andWhere(self::$table. '_d' . $depth . '.media_name', '=', $name);
$objs = self::getAllByQuery($query, RelationType::ALL, $depth);

View File

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

View File

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

View File

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

View File

@ -5,6 +5,6 @@ use phpOMS\Uri\UriFactory;
?>
<section id="mediaFile" class="portlet">
<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>
</section>

View File

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