Skip to content

Commit

Permalink
Drop legacy PHP (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul authored Jul 31, 2024
1 parent 2352bc0 commit e7b6ab0
Show file tree
Hide file tree
Showing 292 changed files with 1,465 additions and 5,290 deletions.
66 changes: 45 additions & 21 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ jobs:
fail-fast: false
matrix:
php-versions:
- "7.4"
- "8.0"
- "8.1"
# - '8.2'
- "8.2"
- "8.3"
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
Expand All @@ -34,11 +32,9 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- run: composer self-update --2
Expand All @@ -49,28 +45,56 @@ jobs:
- name: Info
run: composer info
- name: Run Tests
run: php vendor/bin/grumphp run -vvv
run: php vendor/bin/grumphp run # -vvv
- name: Install Composer dependencies without dev
run: rm -fR vendor && composer install --no-progress --prefer-dist --optimize-autoloader --no-dev
if: matrix.php-versions == '7.4'
- name: Install Box
run: wget https://github.com/box-project/box/releases/download/3.13.0/box.phar
if: matrix.php-versions == '7.4'
if: matrix.php-versions == '8.1'
- name: Compile phar
run: php box.phar compile
if: matrix.php-versions == '7.4'
- name: Compile Result
run: ls -lah
if: matrix.php-versions == '7.4'
run: wget https://github.com/box-project/box/releases/download/4.5.1/box.phar && php box.phar compile
if: matrix.php-versions == '8.1'
# - name: Compile Result
# run: ls -lah
# if: matrix.php-versions == '8.1'
- name: Compile Result Upload
if: matrix.php-versions == '7.4'
uses: actions/upload-artifact@v3
if: matrix.php-versions == '8.1'
uses: actions/upload-artifact@v4
with:
name: jeeves_new.phar
path: jeeves.phar
test:
runs-on: ubuntu-latest
needs: ["build"]
strategy:
fail-fast: false
matrix:
php-versions:
- "8.1"
- "8.2"
- "8.3"
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: jeeves_new.phar
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, mysql
- name: Prepare test
run: mv .jeeves.phpunit_v1.yaml .jeeves.yaml
- name: Test phar
run: php jeeves.phar generate
release:
runs-on: ubuntu-latest
needs: ["test"]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v4
with:
name: jeeves_new.phar
- name: Upload to Releases
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && matrix.php-versions == '7.4'
with:
files: jeeves.phar
token: ${{ secrets.token }}
78 changes: 0 additions & 78 deletions .jeeves.phpunit_v0.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions .jeeves.phpunit_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ Mygento:
columns: ["city"]
IX_ACTIVE:
columns: ["is_active"]
Obsolete:
settings:
php_version: "7.3"
columns:
id:
type: int
pk: true
unsigned: true
comment: "Banner ID"
name:
type: varchar
Card:
api: true
cacheable: true
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
],
"description": "cli tool to generate M2 code",
"require": {
"symfony/console": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/yaml": "^5.0",
"symfony/console": "^6.0",
"symfony/filesystem": "^6.0",
"symfony/yaml": "^6.0",
"sabre/xml": "^4.0",
"nette/php-generator": "^3.0|^4.0",
"consolidation/self-update": "^2.0.3",
"mygento/coding-standard": "~2.14.0-beta5"
"nette/php-generator": "^4.1",
"consolidation/self-update": "^2.2.0",
"mygento/coding-standard": "~2.14.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": { "Mygento\\Jeeves\\": "src/Jeeves" }
},
"config": {
"platform": {
"php": "7.4.20"
"php": "8.1.20"
},
"allow-plugins": {
"phpro/grumphp": true
Expand Down
6 changes: 3 additions & 3 deletions src/Jeeves/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Application extends BaseApplication
{
public const GEN = 'generate';
public const DS = DIRECTORY_SEPARATOR;
public const VERSION = '1.0.0';
public const VERSION = '1.1.0';
public const NAME = 'Jeeves';

/**
Expand All @@ -31,7 +31,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function run(InputInterface $input = null, OutputInterface $output = null)
public function run(InputInterface $input = null, OutputInterface $output = null): int
{
if (null === $output) {
$output = Factory::createOutput();
Expand Down Expand Up @@ -71,7 +71,7 @@ public function getIO()
/**
* Initializes all commands.
*/
protected function getDefaultCommands()
protected function getDefaultCommands(): array
{
$selfUpdate = new SelfUpdateCommand(self::NAME, self::VERSION, 'mygento/jeeves');

Expand Down
2 changes: 1 addition & 1 deletion src/Jeeves/Console/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function writeFile($path, $content)
$io = $this->getIO();
$io->write(sprintf('Creating: <info>%s</info>.', $path));

return $fs->dumpFile($path, $content);
$fs->dumpFile($path, $content);
}

protected function runCodeStyleFixer()
Expand Down
12 changes: 11 additions & 1 deletion src/Jeeves/Console/Command/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$payment = false;
foreach ($config as $vendor => $mod) {
foreach ($mod as $module => $ent) {
if (isset($ent['crud'])) {
if (isset($ent['entities'])) {
$crud = true;
}
if (isset($ent['shipping'])) {
Expand All @@ -53,6 +53,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$input = new ArrayInput($arguments);
$command->run($input, $output);
}
if ($shipping) {
$command = $this->getApplication()->find('generate-shipping');

$arguments = [
'command' => 'generate-shipping',
];

$input = new ArrayInput($arguments);
$command->run($input, $output);
}

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Jeeves/Generators/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ class Common
protected const N = 'name';
protected const V = 'value';

protected function hasTypes(string $version): bool
{
return version_compare($version, '7.4.0', '>=');
}

protected function hasConstructorProp(string $version): bool
{
return version_compare($version, '8.0.0', '>=');
Expand All @@ -31,6 +26,11 @@ protected function hasReadOnlyClass(string $version): bool
return version_compare($version, '8.2.0', '>=');
}

protected function hasTypedConst(string $version): bool
{
return version_compare($version, '8.3.0', '>=');
}

protected function getService(): Service
{
$service = new Service();
Expand Down
33 changes: 8 additions & 25 deletions src/Jeeves/Generators/Crud/Controllers/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function genAdminNewController(
string $rootNamespace,
string $phpVersion = PHP_VERSION
): PhpNamespace {
$typehint = $this->hasTypes($phpVersion);
$constructorProp = $this->hasConstructorProp($phpVersion);
$readonlyProp = $this->hasReadOnlyProp($phpVersion);

Expand All @@ -27,11 +26,7 @@ public function genAdminNewController(
if (!$constructorProp) {
$forward = $class->addProperty('resultForwardFactory')->setVisibility('private');

if ($typehint) {
$forward->setType('\Magento\Backend\Model\View\Result\ForwardFactory');
} else {
$forward->addComment('@var \Magento\Backend\Model\View\Result\ForwardFactory');
}
$forward->setType('\Magento\Backend\Model\View\Result\ForwardFactory');
}

$body = 'parent::__construct($repository, $coreRegistry, $context);';
Expand All @@ -41,19 +36,11 @@ public function genAdminNewController(
$construct = $class->addMethod('__construct')
->setBody($body);

if ($typehint) {
$namespace->addUse($rootNamespace . '\Controller\Adminhtml\\' . $entity);
$namespace->addUse($repository);
$namespace->addUse('\Magento\Framework\Registry');
$namespace->addUse('\Magento\Backend\App\Action\Context');
$namespace->addUse('\Magento\Backend\Model\View\Result\ForwardFactory');
} else {
$construct
->addComment('@param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory')
->addComment('@param ' . $repository . ' $repository')
->addComment('@param \Magento\Framework\Registry $coreRegistry')
->addComment('@param \Magento\Backend\App\Action\Context $context');
}
$namespace->addUse($rootNamespace . '\Controller\Adminhtml\\' . $entity);
$namespace->addUse($repository);
$namespace->addUse('\Magento\Framework\Registry');
$namespace->addUse('\Magento\Backend\App\Action\Context');
$namespace->addUse('\Magento\Backend\Model\View\Result\ForwardFactory');

if ($constructorProp) {
$construct
Expand All @@ -76,12 +63,8 @@ public function genAdminNewController(
. '$resultForward = $this->resultForwardFactory->create();' . PHP_EOL
. 'return $resultForward->forward(\'edit\');');

if ($typehint) {
$execute->setReturnType('\Magento\Framework\Controller\ResultInterface');
$namespace->addUse('\Magento\Framework\Controller\ResultInterface');
} else {
$execute->addComment('@return \Magento\Framework\Controller\ResultInterface');
}
$execute->setReturnType('\Magento\Framework\Controller\ResultInterface');
$namespace->addUse('\Magento\Framework\Controller\ResultInterface');

return $namespace;
}
Expand Down
Loading

0 comments on commit e7b6ab0

Please sign in to comment.