Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul committed Jul 31, 2024
1 parent 2352bc0 commit 5d813c0
Show file tree
Hide file tree
Showing 213 changed files with 188 additions and 4,133 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +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
Expand All @@ -34,11 +33,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 @@ -52,25 +49,25 @@ jobs:
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'
if: matrix.php-versions == '8.1'
- name: Install Box
run: wget https://github.com/box-project/box/releases/download/3.13.0/box.phar
if: matrix.php-versions == '7.4'
run: wget https://github.com/box-project/box/releases/download/4.5.1/box.phar
if: matrix.php-versions == '8.1'
- name: Compile phar
run: php box.phar compile
if: matrix.php-versions == '7.4'
if: matrix.php-versions == '8.1'
- name: Compile Result
run: ls -lah
if: matrix.php-versions == '7.4'
if: matrix.php-versions == '8.1'
- name: Compile Result Upload
if: matrix.php-versions == '7.4'
if: matrix.php-versions == '8.1'
uses: actions/upload-artifact@v3
with:
name: jeeves_new.phar
path: jeeves.phar
- name: Upload to Releases
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && matrix.php-versions == '7.4'
if: startsWith(github.ref, 'refs/tags/') && matrix.php-versions == '8.1'
with:
files: jeeves.phar
token: ${{ secrets.token }}
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
4 changes: 2 additions & 2 deletions src/Jeeves/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 28 additions & 28 deletions src/Jeeves/Generators/Crud/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function genRepository(
$typehint = $this->hasTypes($phpVersion);
$constructorProp = $this->hasConstructorProp($phpVersion);
$readonlyProp = $this->hasReadOnlyProp($phpVersion);
$readonlyClass = false; //$this->hasReadOnlyClass($phpVersion);
$readonlyClass = $this->hasReadOnlyClass($phpVersion);

$namespace = new PhpNamespace($rootNamespace . '\Model');
$namespace->addUse('\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface');
Expand All @@ -34,8 +34,8 @@ public function genRepository(
$class->setImplements([$repoInterface]);
$class->setComment('@SuppressWarnings(PHPMD.CouplingBetweenObjects)');

if ($readonlyClass) { /** @phpstan-ignore-line */
$class->setReadOnly($readonlyClass); /** @phpstan-ignore-line */
if ($readonlyClass) {
$class->setReadOnly($readonlyClass);
}

if (!$constructorProp) {
Expand Down Expand Up @@ -84,22 +84,22 @@ public function genRepository(
if ($constructorProp) {
$construct
->addPromotedParameter('resource')
->setReadOnly($readonlyProp && !$readonlyClass) /** @phpstan-ignore-line */
->setReadOnly($readonlyProp && !$readonlyClass)
->setPrivate()
->setType($resource);
$construct
->addPromotedParameter('collectionFactory')
->setReadOnly($readonlyProp && !$readonlyClass) /** @phpstan-ignore-line */
->setReadOnly($readonlyProp && !$readonlyClass)
->setPrivate()
->setType($collection . 'Factory');
$construct
->addPromotedParameter('entityFactory')
->setReadOnly($readonlyProp && !$readonlyClass) /** @phpstan-ignore-line */
->setReadOnly($readonlyProp && !$readonlyClass)
->setPrivate()
->setType($entityInterface . 'Factory');
$construct
->addPromotedParameter('searchResultsFactory')
->setReadOnly($readonlyProp && !$readonlyClass) /** @phpstan-ignore-line */
->setReadOnly($readonlyProp && !$readonlyClass)
->setPrivate()
->setType($results . 'Factory');
} else {
Expand Down Expand Up @@ -132,7 +132,7 @@ public function genRepository(
if ($constructorProp) {
$construct
->addPromotedParameter('storeManager')
->setReadOnly($readonlyProp && !$readonlyClass) /** @phpstan-ignore-line */
->setReadOnly($readonlyProp && !$readonlyClass)
->setPrivate()
->setType('\Magento\Store\Model\StoreManagerInterface');
} else {
Expand All @@ -157,7 +157,7 @@ public function genRepository(

if ($constructorProp) {
$construct->addPromotedParameter('collectionProcessor')
->setReadOnly($readonlyProp && !$readonlyClass) /** @phpstan-ignore-line */
->setReadOnly($readonlyProp && !$readonlyClass)
->setPrivate()
->setType('Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface');
} else {
Expand Down Expand Up @@ -218,17 +218,17 @@ public function genRepository(

$save->addBody(
($withStore ? 'if (empty($entity->getStoreId())) {' . PHP_EOL
. self::TAB . '$entity->setStoreId([$this->storeManager->getStore()->getId()]);' . PHP_EOL
. '}' . PHP_EOL : '')
. 'try {' . PHP_EOL
. self::TAB . '$this->resource->save($entity);' . PHP_EOL
. '} catch (\Exception $exception) {' . PHP_EOL
. self::TAB . 'throw new CouldNotSaveException(' . PHP_EOL
. self::TAB . self::TAB . '__(\'Could not save the ' . $print . '\'),' . PHP_EOL
. self::TAB . self::TAB . '$exception' . PHP_EOL
. self::TAB . ');' . PHP_EOL
. '}' . PHP_EOL
. 'return $entity;'
. self::TAB . '$entity->setStoreId([$this->storeManager->getStore()->getId()]);' . PHP_EOL
. '}' . PHP_EOL : '')
. 'try {' . PHP_EOL
. self::TAB . '$this->resource->save($entity);' . PHP_EOL
. '} catch (\Exception $exception) {' . PHP_EOL
. self::TAB . 'throw new CouldNotSaveException(' . PHP_EOL
. self::TAB . self::TAB . '__(\'Could not save the ' . $print . '\'),' . PHP_EOL
. self::TAB . self::TAB . '$exception' . PHP_EOL
. self::TAB . ');' . PHP_EOL
. '}' . PHP_EOL
. 'return $entity;'
);

$delete = $class->addMethod('delete')->setVisibility('public');
Expand Down Expand Up @@ -290,14 +290,14 @@ public function genRepository(
}

$getList->setBody('/** @var ' . $collection . ' $collection */' . PHP_EOL
. '$collection = $this->collectionFactory->create();' . PHP_EOL . PHP_EOL
. '$this->collectionProcessor->process($criteria, $collection);' . PHP_EOL . PHP_EOL
. '/** @var ' . $namespace->simplifyName($results) . ' $searchResults */' . PHP_EOL
. '$searchResults = $this->searchResultsFactory->create();' . PHP_EOL
. '$searchResults->setSearchCriteria($criteria);' . PHP_EOL
. '$searchResults->setItems($collection->getItems());' . PHP_EOL
. '$searchResults->setTotalCount($collection->getSize());' . PHP_EOL
. 'return $searchResults;');
. '$collection = $this->collectionFactory->create();' . PHP_EOL . PHP_EOL
. '$this->collectionProcessor->process($criteria, $collection);' . PHP_EOL . PHP_EOL
. '/** @var ' . $namespace->simplifyName($results) . ' $searchResults */' . PHP_EOL
. '$searchResults = $this->searchResultsFactory->create();' . PHP_EOL
. '$searchResults->setSearchCriteria($criteria);' . PHP_EOL
. '$searchResults->setItems($collection->getItems());' . PHP_EOL
. '$searchResults->setTotalCount($collection->getSize());' . PHP_EOL
. 'return $searchResults;');

return $namespace;
}
Expand Down
42 changes: 9 additions & 33 deletions src/Jeeves/IO/BaseIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ abstract class BaseIO implements IOInterface, LoggerInterface
{
/**
* System is unusable.
*
* @param string $message
* @param array $context
*/
public function emergency($message, array $context = [])
public function emergency(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::EMERGENCY, $message, $context);
}
Expand All @@ -23,11 +20,8 @@ public function emergency($message, array $context = [])
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
*/
public function alert($message, array $context = [])
public function alert(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::ALERT, $message, $context);
}
Expand All @@ -36,23 +30,17 @@ public function alert($message, array $context = [])
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
*/
public function critical($message, array $context = [])
public function critical(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::CRITICAL, $message, $context);
}

/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
*/
public function error($message, array $context = [])
public function error(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::ERROR, $message, $context);
}
Expand All @@ -66,18 +54,15 @@ public function error($message, array $context = [])
* @param string $message
* @param array $context
*/
public function warning($message, array $context = [])
public function warning(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::WARNING, $message, $context);
}

/**
* Normal but significant events.
*
* @param string $message
* @param array $context
*/
public function notice($message, array $context = [])
public function notice(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::NOTICE, $message, $context);
}
Expand All @@ -86,34 +71,25 @@ public function notice($message, array $context = [])
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
*/
public function info($message, array $context = [])
public function info(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::INFO, $message, $context);
}

/**
* Detailed debug information.
*
* @param string $message
* @param array $context
*/
public function debug($message, array $context = [])
public function debug(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::DEBUG, $message, $context);
}

/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*/
public function log($level, $message, array $context = [])
public function log($level, string|\Stringable $message, array $context = []): void
{
if (in_array($level, [LogLevel::EMERGENCY, LogLevel::ALERT, LogLevel::CRITICAL, LogLevel::ERROR])) {
$this->writeError('<error>' . $message . '</error>', true, self::NORMAL);
Expand Down
Loading

0 comments on commit 5d813c0

Please sign in to comment.