Commit b6e68031 authored by Gatterdam Patrick's avatar Gatterdam Patrick
Browse files

Merge branch 'fix/media-struct-converter' into 'master'

Fix wrong return type of MediaModelFrontendService::getMediaStruct

See merge request shopware/plugins/RicoGrids!89
parents d0ef6d35 fd4c59bd
version: '2.3'
services:
#======================================================
# Build
#======================================================
build:
image: composer:2.0
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
composer install --no-scripts;
"
#======================================================
# Build FE
#======================================================
build-fe:
image: node:alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: npm install
#======================================================
# Lint PHP
#======================================================
lint-php:
image: overtrue/phplint:7.4
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
#======================================================
# Lint js-hint
#======================================================
js-hint:
image: node:alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: node_modules/jshint/bin/jshint --verbose Resources/views/backend/
#======================================================
# Quality - php-cs-fixer
#======================================================
php-cs-fixer:
image: cytopia/php-cs-fixer:2-php7.2
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: fix --dry-run --diff --allow-risky=yes
#======================================================
# Quality - php-cs-fixer
#======================================================
php-cs-fixer-fix:
image: cytopia/php-cs-fixer:2-php7.2
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: fix --allow-risky=yes
#!/usr/bin/env bash
# Function to write a .env file in Build/docker
# This is read by docker-compose and vars defined here are
# used in .Ci/Docker/docker-compose.yml
# Function to write a .env file in Build/testing-docker
setUpDockerComposeDotEnv() {
[ -e .env ] && rm .env
echo "TEST_FILE=${TEST_FILE}" >>.env
echo "ROOT_DIR=${ROOT_DIR}" >>.env
echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >>.env
echo "PHP_VERSION=${PHP_VERSION}" >>.env
}
# Function to get the real path on mac os.
realpath() {
if ! pushd $1 &>/dev/null; then
pushd ${1##*/} &>/dev/null
echo $(pwd -P)/${1%/*}
else
pwd -P
fi
popd >/dev/null
}
# Load help text into $HELP
read -r -d '' HELP <<EOF
Extension test runner. Execute unit test suite and some other details.
Usage: $0 [options] [file]
Options:
-s <...>
Specifies which test suite to run
- build (default): Builds the project (composer)
- build-fe: Builds the project (grunt)
- lint: Lints php and typoscript files. Also finds usages of debug calls.
- qa: executes code quality checks
- fix
-p <7.2>
Specifies the PHP minor version to be used
- 7.2 (default): use PHP 7.2
-h
Show this help.
Examples:
# Run unit tests
.Ci/Scripts/console.sh -s build
EOF
# Test if docker-compose exists, else exit out with error
if ! type "docker-compose" >/dev/null; then
echo "This script relies on docker and docker-compose. Please install" >&2
exit 1
fi
# Go to the directory this script is located, so everything else is relative
# to this dir, no matter from where this script is called.
THIS_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$THIS_SCRIPT_DIR" || exit 1
# Go to directory that contains the local docker-compose.yml file
cd ../Docker || exit 1
# Option defaults
ROOT_DIR=$(realpath $PWD"/../../")
TEST_SUITE="build"
PHP_VERSION="7.2"
EXTRA_TEST_OPTIONS=""
# Option parsing
# Reset in case getopts has been used previously in the shell
OPTIND=1
# Array for invalid options
INVALID_OPTIONS=()
# Simple option parsing based on getopts (! not getopt)
while getopts ":s:d:p:e:xy:huv" OPT; do
case ${OPT} in
s)
TEST_SUITE=${OPTARG}
;;
p)
PHP_VERSION=${OPTARG}
;;
e)
EXTRA_TEST_OPTIONS=${OPTARG}
;;
h)
echo "${HELP}"
exit 0
;;
\?)
INVALID_OPTIONS+=(${OPTARG})
;;
:)
INVALID_OPTIONS+=(${OPTARG})
;;
esac
done
# Exit on invalid options
if [ ${#INVALID_OPTIONS[@]} -ne 0 ]; then
echo "Invalid option(s):" >&2
for I in "${INVALID_OPTIONS[@]}"; do
echo "-"${I} >&2
done
echo >&2
echo "${HELP}" >&2
exit 1
fi
# Set $1 to first mass argument, this is the optional test file or test directory to execute
shift $((OPTIND - 1))
if [ -n "${1}" ]; then
TEST_FILE="${ROOT_DIR}/${1}"
else
case ${TEST_SUITE} in
unit)
TEST_FILE="${ROOT_DIR}/tests/Unit"
;;
esac
fi
# Suite execution
case ${TEST_SUITE} in
build)
setUpDockerComposeDotEnv
docker-compose run build
SUITE_EXIT_CODE=$?
docker-compose down
;;
build-fe)
setUpDockerComposeDotEnv
docker-compose run build-fe
SUITE_EXIT_CODE=$?
docker-compose down
;;
lint)
setUpDockerComposeDotEnv
docker-compose run lint-php
SUITE_EXIT_CODE=$?
docker-compose down
docker-compose run js-hint
SUITE_EXIT_CODE=$?
docker-compose down
;;
qa)
setUpDockerComposeDotEnv
docker-compose run php-cs-fixer
SUITE_EXIT_CODE=$?
docker-compose down
;;
fix)
setUpDockerComposeDotEnv
docker-compose run php-cs-fixer-fix
SUITE_EXIT_CODE=$?
docker-compose down
;;
*)
echo "Invalid -s option argument ${TEST_SUITE}" >&2
echo >&2
echo "${HELP}" >&2
exit 1
;;
esac
exit $SUITE_EXIT_CODE
/.php_cs.cache
vendor/
\ No newline at end of file
vendor/
composer.lock
.env
phplint.cache
.debug: &debug
image: debian:jessie-slim
stage: debug
dependencies:
- composer-base
before_script:
- mkdir -p debug_logs
artifacts:
name: ${CI_COMMIT_REF_SLUG}-debug_check
expire_in: 2h
when: on_failure
paths:
- debug_logs
cache:
key: ${CI_COMMIT_REF_SLUG}-cache
paths:
- .vendor/
- .node_modules/
stages:
- build
- debug
- lint
- quality
composer-base:
# build
composer:
image: composer:2
stage: build
image: composer:latest
script:
- composer update --no-interaction --ignore-platform-reqs --no-scripts --with-dependencies
- composer install --no-interaction --ignore-platform-reqs --no-scripts
artifacts:
name: ${CI_COMMIT_REF_SLUG}-composer
expire_in: 2h
paths:
- vendor
- composer.lock
cache:
key: ${CI_COMMIT_REF_SLUG}-composer
expire_in: 1 hour
paths:
- vendor
- composer.lock
node-base:
- vendor/
only:
- merge_requests
node:
image: node:alpine
stage: build
script:
- npm i ./.ci
- npm install
artifacts:
name: ${CI_COMMIT_REF_SLUG}-composer
name: ${CI_COMMIT_REF_SLUG}-node
expire_in: 2h
paths:
- node_modules
cache:
key: ${CI_COMMIT_REF_SLUG}-node
policy: push
paths:
- node_modules
- package-lock.json
smarty-debug:
<<: *debug
script:
- grep -r --exclude-dir=vendor -i --include \*.tpl "{debug}" . > debug_logs/smarty_debug.txt || true
- cat debug_logs/smarty_debug.txt
- if (($(wc -l debug_logs/smarty_debug.txt | awk '{print $1}' ) > 0)); then exit "1"; fi
js-debug:
<<: *debug
script:
- grep -r --exclude-dir=vendor -i --include \*.js "window.console.log" . > debug_logs/js_debug.txt || true
- cat debug_logs/js_debug.txt
- if (($(wc -l debug_logs/js_debug.txt | awk '{print $1}' ) > 0)); then exit "1"; fi
php-debug:
<<: *debug
only:
- merge_requests
# lint
lint-php:
image: php:7.2-alpine
stage: lint
script:
- grep -r --exclude-dir=vendor -i --include \*.php "var_dump" . > debug_logs/php_debug.txt || true
- grep -r --exclude-dir=vendor -i --include \*.php "\\Kint::dump" . >> debug_logs/php_debug.txt || true
- cat debug_logs/php_debug.txt
- if (($(wc -l debug_logs/php_debug.txt | awk '{print $1}' ) > 0)); then exit "1"; fi
- php -v | grep '^PHP';
- find . -name \\*.php ! -path "./vendor/\\*" -print0 | xargs -0 -n1 -P4 php -n -c /etc/php/cli-no-xdebug/php.ini -l >/dev/null;
only:
- merge_requests
js-hint:
image: node:alpine
stage: lint
dependencies:
- node-base
script:
- node_modules/jshint/bin/jshint --verbose custom/project
php-lint:
stage: lint
- node_modules/jshint/bin/jshint --verbose Resources/views/backend/
only:
- merge_requests
# quality
php-cs-fixer:
image: php:7.2-alpine
script:
- if find . -type f -name '*.php' -and -not -path vendor -exec php -l {} \; | grep "Parsing error"; then exit 1; fi
js-lint:
image: node:alpine
stage: quality
dependencies:
- node-base
script:
- node_modules/eslint/bin/eslint.js .
php-cs:
stage: quality
image: ekreative/php-cs-fixer:2
dependencies:
- composer-base
script:
- php-cs-fixer fix --allow-risky=yes --format="json" --dry-run .
\ No newline at end of file
- vendor/bin/php-cs-fixer fix --dry-run --diff --allow-risky=yes
only:
- merge_requests
{
"esversion": 6
}
......@@ -50,9 +50,9 @@ return PhpCsFixer\Config::create()
'blank_line_after_opening_tag' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
'yoda_style' => true,
'declare_strict_types' => true,
'psr4' => true,
// 'psr4' => false,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'semicolon_after_instruction' => true,
......
path: ./
jobs: 10
cache: phplint.cache
extensions:
- php
exclude:
- vendor
warning: false
......@@ -146,7 +146,7 @@ class Shopware_Controllers_Backend_RicoGridEntry extends Shopware_Controllers_Ba
{
$metaData = $this->getManager()->getClassMetadata($this->model);
foreach ($metaData->getAssociationMappings() as $mapping) {
if ($mapping['type'] === 1) {
if (1 === $mapping['type']) {
$mappingData = $data[$mapping['fieldName']];
if (array_key_exists(0, $mappingData)) {
$data[$mapping['fieldName']] = $data[$mapping['fieldName']][0];
......@@ -157,7 +157,7 @@ class Shopware_Controllers_Backend_RicoGridEntry extends Shopware_Controllers_Ba
continue;
}
if ($mapping['type'] === 2) {
if (2 === $mapping['type']) {
/**
* @ORM\ManyToOne associations.
*
......@@ -181,7 +181,7 @@ class Shopware_Controllers_Backend_RicoGridEntry extends Shopware_Controllers_Ba
$data[$mapping['fieldName']] = $associationModel;
// unset($data[$field]);
}
} elseif ($mapping['type'] === 3) {
} elseif (3 === $mapping['type']) {
$associationData = $data[$mapping['fieldName']];
$associationModels = [];
foreach ($associationData as $singleData) {
......@@ -202,7 +202,7 @@ class Shopware_Controllers_Backend_RicoGridEntry extends Shopware_Controllers_Ba
*/
protected function getTranslationComponent()
{
if ($this->translation === null) {
if (null === $this->translation) {
$this->translation = $this->container->get('translation');
}
......
......@@ -195,7 +195,7 @@ class Shopware_Controllers_Backend_RicoGrids extends Shopware_Controllers_Backen
*
* So we have to remove the first level of the posted data.
*/
if ($mapping['type'] === ClassMetadataInfo::ONE_TO_ONE) {
if (ClassMetadataInfo::ONE_TO_ONE === $mapping['type']) {
$mappingData = $data[$mapping['fieldName']];
if (array_key_exists(0, (array) $mappingData)) {
$data[$mapping['fieldName']] = $data[$mapping['fieldName']][0];
......@@ -206,7 +206,7 @@ class Shopware_Controllers_Backend_RicoGrids extends Shopware_Controllers_Backen
continue;
}
if ($mapping['type'] === ClassMetadataInfo::MANY_TO_ONE) {
if (ClassMetadataInfo::MANY_TO_ONE === $mapping['type']) {
/**
* @ORM\ManyToOne associations.
*
......@@ -233,7 +233,7 @@ class Shopware_Controllers_Backend_RicoGrids extends Shopware_Controllers_Backen
//remove the foreign key data.
// unset($data[$field]);
}
} elseif ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY) {
} elseif (ClassMetadataInfo::MANY_TO_MANY === $mapping['type']) {
/**
* @ORM\ManyToMany associations.
*
......@@ -271,7 +271,7 @@ class Shopware_Controllers_Backend_RicoGrids extends Shopware_Controllers_Backen
*/
protected function getTranslationComponent()
{
if ($this->translation === null) {
if (null === $this->translation) {
$this->translation = $this->container->get('translation');
}
......
......@@ -74,7 +74,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
$mediaService = $this->getMediaModelFrontendService();
// Validate request arguments.
if ($gridId === 0 || $gridEntryId === 0) {
if (0 === $gridId || 0 === $gridEntryId) {
$this->forward('index', 'error', 'frontend');
}
......@@ -113,7 +113,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
]);
}
protected function getShop(): \Shopware\Models\Shop\Shop
protected function getShop(): Shopware\Models\Shop\Shop
{
/** @var \Shopware\Models\Shop\Shop $shop */
$shop = $this->container->get('shop');
......@@ -121,7 +121,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
return $shop;
}
protected function getGridRepository(): \RicoGrids\Repositories\GridRepository
protected function getGridRepository(): RicoGrids\Repositories\GridRepository
{
/** @var \RicoGrids\Repositories\GridRepository $repository */
$repository = $this->getModelManager()->getRepository(\RicoGrids\Models\Grid::class);
......@@ -129,7 +129,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
return $repository;
}
protected function getGridEntryRepository(): \RicoGrids\Repositories\GridEntryRepository
protected function getGridEntryRepository(): RicoGrids\Repositories\GridEntryRepository
{
/** @var \RicoGrids\Repositories\GridEntryRepository $repository */
$repository = $this->getModelManager()->getRepository(\RicoGrids\Models\GridEntry::class);
......@@ -137,7 +137,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
return $repository;
}
protected function getGridMapService(): \RicoGrids\Services\GridMapService
protected function getGridMapService(): RicoGrids\Services\GridMapService
{
/** @var \RicoGrids\Services\GridMapService $service */
$service = $this->container->get('rico_grids.service.grid_map');
......@@ -145,7 +145,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
return $service;
}
protected function getAttributeGetterService(): \RicoGrids\Services\AttributeGetterService
protected function getAttributeGetterService(): RicoGrids\Services\AttributeGetterService
{
/** @var \RicoGrids\Services\AttributeGetterService $service */
$service = $this->container->get('rico_grids.services.attribute_getter_service');
......@@ -153,7 +153,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
return $service;
}
protected function getTranslationOverlayComponent(): \RicoGrids\Components\Translation\TranslationOverlayComponent
protected function getTranslationOverlayComponent(): RicoGrids\Components\Translation\TranslationOverlayComponent
{
/** @var \RicoGrids\Components\Translation\TranslationOverlayComponent $component */
$component = $this->container->get('rico_grids.service.components.translation.translation_overlay_component');
......@@ -161,7 +161,7 @@ class Shopware_Controllers_Frontend_RicoGrid extends Enlight_Controller_Action
return $component;
}
protected function getMediaModelFrontendService(): \RicoGrids\Services\MediaModelFrontendServiceInterface
protected function getMediaModelFrontendService(): RicoGrids\Services\MediaModelFrontendServiceInterface
{
/** @var \RicoGrids\Services\MediaModelFrontendServiceInterface $service */
$service = $this->container->get('rico_grids.service.media_model_frontend_service');
......
......@@ -180,7 +180,7 @@ class GridFixture
}
$gridEntry->setBigEntry(false);
$gridEntry->setPosition($x);
if ($x % 8 === 0) {
if (0 === $x % 8) {
$gridEntry->setBigEntry(true);
}
$gridEntry->setGrid($grid);
......
......@@ -363,7 +363,7 @@ class Grid extends ModelEntity
public function sortEntries(): void
{
if ($this->getOrderType() === self::SORT_POSITION) {
if (self::SORT_POSITION === $this->getOrderType()) {
$entries = $this->getGridEntries()->toArray();
usort($entries, function ($a, $b) {
......@@ -382,7 +382,7 @@ class Grid extends ModelEntity
/* @var GridEntry $b */
return strcmp(strtolower($a->getName()), strtolower($b->getName()));
});
if ($this->getOrderType() === self::SORT_NAME_DESC) {
if (self::SORT_NAME_DESC === $this->getOrderType()) {
$entries = array_reverse($entries);
}
$this->setGridEntries(new ArrayCollection($entries));
......
......@@ -94,7 +94,7 @@ class GridMapService
$this->colMax = 4;
}
if ($grid->getType() === 'accordion') {
if ('accordion' === $grid->getType()) {
$gridMap = $this->buildByAccordion($grid);
} else {
$gridMap = $this->buildByDefault($grid->getGridEntries());
......@@ -111,7 +111,7 @@ class GridMapService
$gridMap['grid']->setGridEntries($gridEntries ?? []);
}
return $grid->getType() === 'accordion' ? $this->convertAccordionMapToArrayRepresentation($gridMap) :
return 'accordion' === $grid->getType() ? $this->convertAccordionMapToArrayRepresentation($gridMap) :
$this->convertDefaultMapToArrayRepresentation($gridMap);
}
......@@ -124,7 +124,7 @@ class GridMapService
$accordions = [];
/** @var GridEntry $gridEntry */
foreach ($grid->getGridEntries() as $gridEntry) {
if (!$gridEntry->isActive() && $gridEntry->getAccordion() != '' && $gridEntry->getAccordion() !== null) {
if (!$gridEntry->isActive() && '' != $gridEntry->getAccordion() && null !== $gridEntry->getAccordion()) {
continue;
}
if ($accordions[$gridEntry->getAccordion()]) {
......@@ -285,7 +285,7 @@ class GridMapService
*/
private function getUnblocked($positionY, $positionX, $isBig = false)
{
while ($this->blocked[$positionY][$positionX] === true) {
while (true === $this->blocked[$positionY][$positionX]) {
++$positionY;
if ($positionY >= $this->colMax + 1) {
$positionY = 1;
......
......@@ -85,7 +85,7 @@ class MediaModelFrontendService implements MediaModelFrontendServiceInterface
return $result;
}
protected function getMediaStruct(int $mediaId): Media
protected function getMediaStruct(int $mediaId): ?Media
{
return $this->mediaService->get($mediaId, $this->getContext());
}
......
......@@ -92,7 +92,7 @@ class RewriteTableSubscriber implements SubscriberInterface
$subject = $args->getSubject();
$request = $subject->Request();
if ($request->getActionName() !== 'load') {
if ('load' !== $request->getActionName()) {
return;