Skip to content

Commit

Permalink
Merge pull request #5238 from Catrobat/stormClean
Browse files Browse the repository at this point in the history
Automatic Code Clean up from Phpstorm IDE
  • Loading branch information
dmetzner authored Sep 11, 2024
2 parents 2af75cc + b4f39f4 commit 926b773
Show file tree
Hide file tree
Showing 118 changed files with 890 additions and 429 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ yarn-error.log

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> friends-of-behat/symfony-extension ###
Expand Down
85 changes: 40 additions & 45 deletions bin/checkCatroidRepositoryForNewBricks
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ $url2 = 'https://raw.githubusercontent.com/Catrobat/Catroid/3204098b163b248cd0bb
$catroid_data_set_1 = file_get_contents($url1);
$catroid_data_set_2 = file_get_contents($url2);

if (!$catroid_data_set_1)
{
if (!$catroid_data_set_1) {
echo 'XstreamSerializer.java could not be downloaded';
exit(1);
}

if (!$catroid_data_set_2)
{
if (!$catroid_data_set_2) {
echo 'CategoryBricksFactory.java could not be downloaded';
exit(1);
}
Expand All @@ -49,8 +47,7 @@ asort($all_catroid_bricks_and_scripts);
$path = './src/Project/CatrobatCode/Parser/Constants.php';
$catroweb_data_set = file_get_contents($path);

if (!$catroweb_data_set)
{
if (!$catroweb_data_set) {
echo "Constants.php couldn't be read";
exit(1);
}
Expand All @@ -66,49 +63,47 @@ asort($all_catroweb_bricks_and_scripts);
$diff_result_not_in_app_but_web = array_diff($all_catroweb_bricks_and_scripts, $all_catroid_bricks_and_scripts);
$diff_result_not_in_web_but_app = array_diff($all_catroid_bricks_and_scripts, $all_catroweb_bricks_and_scripts);

if (count($diff_result_not_in_web_but_app) > 0 || count($diff_result_not_in_app_but_web) > 0)
{
$message = '';
if (count($diff_result_not_in_web_but_app) > 0 || count($diff_result_not_in_app_but_web) > 0) {

$message .= count($diff_result_not_in_app_but_web) > 0 ?
"These blocks are only defined in catroweb but not in the app: \n".
print_r($diff_result_not_in_app_but_web, true)."\n".
$message = count($diff_result_not_in_app_but_web) > 0 ?
"These blocks are only defined in catroweb but not in the app: \n" .
print_r($diff_result_not_in_app_but_web, true) . "\n" .

'//'."\n".
'// For new deprecated bricks: '."\n".
'//'."\n".
"// 1) Set the correct Brick/Scripts classes image to 'Constants::DEPRECATED_SCRIPT_IMG'"."\n".
"// The block should from now count to the 'other' category."."\n".
'// E.g look at src/Catrobat/CatrobatCode/Parser/Scripts/CollisionScript.php'."\n".
'//'."\n".
'// 2) Finally add it in this test to the deprecated_bricks array'."\n".
'//'."\n\n" : '';
'//' . "\n" .
'// For new deprecated bricks: ' . "\n" .
'//' . "\n" .
"// 1) Set the correct Brick/Scripts classes image to 'Constants::DEPRECATED_SCRIPT_IMG'" . "\n" .
"// The block should from now count to the 'other' category." . "\n" .
'// E.g look at src/Catrobat/CatrobatCode/Parser/Scripts/CollisionScript.php' . "\n" .
'//' . "\n" .
'// 2) Finally add it in this test to the deprecated_bricks array' . "\n" .
'//' . "\n\n" : '';

$message .= count($diff_result_not_in_web_but_app) > 0 ?
"These blocks are only defined in catroid but not in the web: \n".
print_r($diff_result_not_in_web_but_app, true)."\n".
'//'."\n".
'// For new bricks - Add the Brick/Script! '."\n".
'//'."\n".
'// 1) Create necessary Constants in src/Catrobat/CatrobatCode/Parser/Constants.php'."\n".
'//'."\n".
'// 2) Create the new brick/script class in src/Catrobat/CatrobatCode/Parser/(Scripts|Bricks)'."\n".
"// Make sure to set the correct img Constant -> that's defining the category of this new block"."\n".
'//'."\n".
'// 3) If it is a NEW img_constant(=category) make sure to add the new case in'."\n".
'// src/Catrobat/CatrobatCode/Parser/CodeStatistic.php updateBrickStatistic(...)'."\n".
'//'."\n".
'// 4) Make sure to add the new case in'."\n".
'// src/Catrobat/CatrobatCode/Parser/Bricks/BrickFactory.php generate(...) or'."\n".
'// src/Catrobat/CatrobatCode/Parser/Scripts/ScriptFactory.php generate(...)'."\n".
'//'."\n".
'// 5) Write a test to check the code statistics of the new block script!!'."\n".
'// -> Create project with app (E.g. upload & download it)'."\n".
'// put project file into tests/testdata/DataFixtures/CodeStatistics/'."\n".
'// write the test in tests/BehatFeatures/web/code_statistics.feature'."\n".
'//'."\n".
'// Now should not only this test case work, the new block is implemented and tested in catroweb'."\n".
'//'."\n\n" : '';
"These blocks are only defined in catroid but not in the web: \n" .
print_r($diff_result_not_in_web_but_app, true) . "\n" .
'//' . "\n" .
'// For new bricks - Add the Brick/Script! ' . "\n" .
'//' . "\n" .
'// 1) Create necessary Constants in src/Catrobat/CatrobatCode/Parser/Constants.php' . "\n" .
'//' . "\n" .
'// 2) Create the new brick/script class in src/Catrobat/CatrobatCode/Parser/(Scripts|Bricks)' . "\n" .
"// Make sure to set the correct img Constant -> that's defining the category of this new block" . "\n" .
'//' . "\n" .
'// 3) If it is a NEW img_constant(=category) make sure to add the new case in' . "\n" .
'// src/Catrobat/CatrobatCode/Parser/CodeStatistic.php updateBrickStatistic(...)' . "\n" .
'//' . "\n" .
'// 4) Make sure to add the new case in' . "\n" .
'// src/Catrobat/CatrobatCode/Parser/Bricks/BrickFactory.php generate(...) or' . "\n" .
'// src/Catrobat/CatrobatCode/Parser/Scripts/ScriptFactory.php generate(...)' . "\n" .
'//' . "\n" .
'// 5) Write a test to check the code statistics of the new block script!!' . "\n" .
'// -> Create project with app (E.g. upload & download it)' . "\n" .
'// put project file into tests/testdata/DataFixtures/CodeStatistics/' . "\n" .
'// write the test in tests/BehatFeatures/web/code_statistics.feature' . "\n" .
'//' . "\n" .
'// Now should not only this test case work, the new block is implemented and tested in catroweb' . "\n" .
'//' . "\n\n" : '';

echo $message;
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ services:
###> symfony/mailer ###
mailer:
image: schickling/mailcatcher
ports: [1025, 1080]
ports: ['1025', '1080']
###< symfony/mailer ###
12 changes: 6 additions & 6 deletions docker/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- chrome.catroweb
- elasticsearch
ports:
- 8080:80
- '8080:80'
volumes:
#
# Changes to the following files are shared between host and container.
Expand Down Expand Up @@ -100,7 +100,7 @@ services:
container_name: db.catroweb.dev
shm_size: '2gb'
ports:
- 3306
- '3306'
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
Expand All @@ -127,14 +127,14 @@ services:
'--no-sandbox',
]
ports:
- 9222
- '9222'

db.catroweb.test:
image: mariadb:10.11
container_name: db.catroweb.test
shm_size: '2gb'
ports:
- 3306
- '3306'
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
Expand All @@ -150,7 +150,7 @@ services:
- PMA_ARBITRARY=1
restart: always
ports:
- 8081:80
- '8081:80'
volumes:
- /sessions
external_links:
Expand All @@ -177,7 +177,7 @@ services:
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
- '9200:9200'

volumes:
esdata1:
Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- chrome.catroweb
- elasticsearch
ports:
- 8080:80
- '8080:80'

# --- Tests:

Expand All @@ -41,14 +41,14 @@ services:
'--no-sandbox',
]
ports:
- 9222
- '9222'

db.catroweb.test:
image: mariadb:10.11
container_name: db.catroweb.test
shm_size: '2gb'
ports:
- 3306
- '3306'
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
Expand All @@ -71,7 +71,7 @@ services:
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
- '9200:9200'

volumes:
esdata1:
Expand Down
48 changes: 48 additions & 0 deletions src/Admin/ApkGeneration/ApkAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Admin\ApkGeneration;

use App\DB\Entity\Project\Program;
use App\Storage\ScreenshotRepository;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;

/**
* @phpstan-extends AbstractAdmin<Program>
*/
class ApkAdmin extends AbstractAdmin
{
#[\Override]
protected function configureDefaultSortValues(array &$sortValues): void
{
$sortValues[DatagridInterface::SORT_BY] = 'apk_request_time';
$sortValues[DatagridInterface::SORT_ORDER] = 'DESC';
}

public function __construct(
private readonly ScreenshotRepository $screenshot_repository,
) {
}

public function getThumbnailImageUrl(Program $object): string
{
return '/'.$this->screenshot_repository->getThumbnailWebPath($object->getId());
}

#[\Override]
protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
{
/** @var ProxyQuery $query */
$query = parent::configureQuery($query);
$qb = $query->getQueryBuilder();
$qb->andWhere(
$qb->expr()->eq($qb->getRootAliases()[0].'.apk_status', ':apk_status')
);

return $query;
}
}
38 changes: 17 additions & 21 deletions src/Admin/ApkGeneration/ApkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use App\Utils\TimeUtils;
use Doctrine\ORM\EntityManagerInterface;
use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\AdminBundle\Exception\LockException;
use Sonata\AdminBundle\Exception\ModelManagerThrowable;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
Expand All @@ -24,19 +26,18 @@ public function __construct(
) {
}

/**
* @throws LockException
* @throws ModelManagerThrowable
*/
public function resetApkBuildStatusAction(): RedirectResponse
{
/** @var Program|null $project */
/** @var Program $project */
$project = $this->admin->getSubject();

if (null === $project) {
$this->addFlash('sonata_flash_error', "Can't reset APK status");
} else {
$project->setApkStatus(Program::APK_NONE);
$project->setApkRequestTime(null);
$this->admin->update($project);
$this->addFlash('sonata_flash_success', 'Reset APK status of '.$project->getName().' successful');
}
$project->setApkStatus(Program::APK_NONE);
$project->setApkRequestTime(null);
$this->admin->update($project);
$this->addFlash('sonata_flash_success', 'Reset APK status of '.$project->getName().' successful');

return new RedirectResponse($this->admin->generateUrl('list'));
}
Expand All @@ -46,18 +47,13 @@ public function resetApkBuildStatusAction(): RedirectResponse
*/
public function requestApkRebuildAction(): RedirectResponse
{
/** @var Program|null $project */
/** @var Program $project */
$project = $this->admin->getSubject();

if (null === $project) {
$this->addFlash('sonata_flash_error', "Can't trigger APK rebuild");
} else {
$this->jenkins_dispatcher->sendBuildRequest($project->getId());
$project->setApkRequestTime(TimeUtils::getDateTime());
$project->setApkStatus(Program::APK_PENDING);
$this->admin->update($project);
$this->addFlash('sonata_flash_success', 'Requested a rebuild of '.$project->getName());
}
$this->jenkins_dispatcher->sendBuildRequest($project->getId());
$project->setApkRequestTime(TimeUtils::getDateTime());
$project->setApkStatus(Program::APK_PENDING);
$this->admin->update($project);
$this->addFlash('sonata_flash_success', 'Requested a rebuild of '.$project->getName());

return new RedirectResponse($this->admin->generateUrl('list'));
}
Expand Down
36 changes: 2 additions & 34 deletions src/Admin/ApkGeneration/ApkPendingAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
namespace App\Admin\ApkGeneration;

use App\DB\Entity\Project\Program;
use App\Storage\ScreenshotRepository;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
Expand All @@ -17,10 +14,7 @@
use Sonata\Form\Type\DateTimeRangePickerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType;

/**
* @phpstan-extends AbstractAdmin<Program>
*/
class ApkPendingAdmin extends AbstractAdmin
class ApkPendingAdmin extends ApkAdmin
{
#[\Override]
protected function generateBaseRouteName(bool $isChildAdmin = false): string
Expand All @@ -34,38 +28,12 @@ protected function generateBaseRoutePattern(bool $isChildAdmin = false): string
return 'catrobat/apk/pending';
}

#[\Override]
protected function configureDefaultSortValues(array &$sortValues): void
{
$sortValues[DatagridInterface::SORT_BY] = 'apk_request_time';
$sortValues[DatagridInterface::SORT_ORDER] = 'DESC';
}

public function __construct(
private readonly ScreenshotRepository $screenshot_repository,
) {
}

/**
* @param Program $object
*/
public function getThumbnailImageUrl($object): string
{
return '/'.$this->screenshot_repository->getThumbnailWebPath($object->getId());
}

#[\Override]
protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
{
/** @var ProxyQuery $query */
$query = parent::configureQuery($query);

$qb = $query->getQueryBuilder();

$qb->andWhere(
$qb->expr()->eq($qb->getRootAliases()[0].'.apk_status', ':apk_status')
);
$qb->setParameter('apk_status', Program::APK_PENDING);
$query->getQueryBuilder()->setParameter('apk_status', Program::APK_PENDING);

return $query;
}
Expand Down
Loading

0 comments on commit 926b773

Please sign in to comment.