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'];

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

@ -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",