Skip to content

Commit

Permalink
Merge pull request #31 from phenomine/analysis-22RNgR
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
fahlisaputra authored Mar 1, 2024
2 parents 6f1a11a + e239d23 commit 582426a
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 98 deletions.
1 change: 0 additions & 1 deletion src/Phenomine/Contracts/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Command extends SymfonyCommand

public function __construct()
{

// call warn production mode if function exists
if (method_exists($this, 'warnProductionMode')) {
$this->warnProductionMode();
Expand Down
11 changes: 5 additions & 6 deletions src/Phenomine/Support/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Phenomine\Support;

use Exception;
use Phenomine\Contracts\Application\ApplicationContract;
use Phenomine\Support\Exceptions\ExceptionHandler;

Expand All @@ -15,7 +14,6 @@ public function run()
$_app = $this;
$this->console->run();
} else {

ob_start(); // start output buffering

global $_app;
Expand All @@ -25,7 +23,8 @@ public function run()
}
}

public function prepare() {
public function prepare()
{
$handler = new ExceptionHandler();

set_error_handler([$handler, 'errorHandler']);
Expand All @@ -36,12 +35,12 @@ public function init()
{
$this->prepare();
new Env(); // load .env file
$env = env('APP_ENV', "");
if ($env == "") {
$env = env('APP_ENV', '');
if ($env == '') {
throw new \Exception('Application environment not set correctly. Please check your configuration before running application.');
}

if ($env == "production") {
if ($env == 'production') {
error_reporting(0);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
Expand Down
60 changes: 41 additions & 19 deletions src/Phenomine/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
namespace Phenomine\Support;

#[\AllowDynamicProperties]
class Collection {
class Collection
{
protected $items;

public function __construct($items = []) {
public function __construct($items = [])
{
$this->items = $items;

return $this;
}

public function __get($name) {
public function __get($name)
{
// remove scalar type
if (is_array($this->items)) {
return (object) $this->items;
Expand All @@ -20,19 +24,22 @@ public function __get($name) {
}
}

public function __set($name, $value) {
public function __set($name, $value)
{
if (!$this->items) {
$this->items = [];
}

$this->items[$name] = $value;
}

public function count() {
public function count()
{
return count($this->items);
}

public function first() {
public function first()
{
if (empty($this->items)) {
return null;
}
Expand All @@ -44,10 +51,12 @@ public function first() {
return $first;
}
}

return null;
}

public function last() {
public function last()
{
if (empty($this->items)) {
return null;
}
Expand All @@ -59,56 +68,69 @@ public function last() {
return $last;
}
}

return null;
}

public function pop() {
public function pop()
{
return array_pop($this->items);
}

public function shift() {
public function shift()
{
return array_shift($this->items);
}

public function unshift($item) {
public function unshift($item)
{
array_unshift($this->items, $item);
}

public function has($key) {
public function has($key)
{
return isset($this->items[$key]);
}

public function remove($key) {
public function remove($key)
{
unset($this->items[$key]);
}

public function keys() {
public function keys()
{
return array_keys($this->items);
}

public function values() {
public function values()
{
return array_values($this->items);
}

public function map($callback) {
public function map($callback)
{
return new static(array_map($callback, $this->items));
}

public function filter($callback) {
public function filter($callback)
{
return new static(array_filter($this->items, $callback));
}

public function each($callback) {
public function each($callback)
{
foreach ($this->items as $key => $item) {
$callback($item, $key);
}
}

public function merge($items) {
public function merge($items)
{
return new static(array_merge($this->items, $items));
}

public function toArray() {
public function toArray()
{
return $this->items;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MakeMigrationCommand extends Command
'm' => 'Make a model for the table',
];


public function handle()
{
if (config('app.env') == 'production') {
Expand All @@ -26,6 +25,7 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}
Expand All @@ -50,12 +50,11 @@ public function handle()
}
$fileModel = File::createFileFromString(base_path('app/Models'), $tableName, '.php');
$stubModel = File::readAndReplace(__DIR__.'../../../../../Stubs/model.stub', [
'class' => $tableName
'class' => $tableName,
]);
File::write($fileModel['file'], $stubModel);
}


$this->info('Migration created successfully');

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}
Expand All @@ -34,20 +35,22 @@ public function handle()
// only support for mysql, mariadb, and postgresql
$db = config('database.driver');
if ($db != 'mysql' && $db != 'mariadb' && $db != 'pgsql') {
$this->error('Database "' . config('database.database') . '" is not exist. Please create it manually.');
$this->error('Database "'.config('database.database').'" is not exist. Please create it manually.');

return;
} else {
// ask for create database
$create = $this->confirm('Database "' . config('database.database') . '" is not exist. Would you like to create it?');
$create = $this->confirm('Database "'.config('database.database').'" is not exist. Would you like to create it?');
if (!$create) {
$this->warn('Migration cancelled.');

return;
}

// create database
$query = 'CREATE DATABASE ' . config('database.database');
$query = 'CREATE DATABASE '.config('database.database');
if ($db == 'mysql' || $db == 'mariadb') {
$query .= ' CHARACTER SET ' . config('database.charset', 'utf8mb4') . ' COLLATE ' . config('database.collation', 'utf8mb4_unicode_ci');
$query .= ' CHARACTER SET '.config('database.charset', 'utf8mb4').' COLLATE '.config('database.collation', 'utf8mb4_unicode_ci');
}

// manually run query
Expand All @@ -61,7 +64,7 @@ public function handle()
$pdo->exec($query);
$pdo = null;

$this->info('Database "' . config('database.database') . '" created.');
$this->info('Database "'.config('database.database').'" created.');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MakeModelCommand extends Command
'm' => 'Make a migration for the table',
];


public function handle()
{
if (config('app.env') == 'production') {
Expand All @@ -26,6 +25,7 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}
Expand All @@ -38,24 +38,23 @@ public function handle()
}
$fileModel = File::createFileFromString(base_path('app/Models'), $tableName, '.php');
$stubModel = File::readAndReplace(__DIR__.'../../../../../Stubs/model.stub', [
'class' => $tableName
'class' => $tableName,
]);
File::write($fileModel['file'], $stubModel);

// check if option migration is set
if ($this->option('m')) {
$name = 'migration_'.date('YmdHis').'_'.$this->argument('table');
$file = File::createFileFromString(base_path('db/migrations'), $name, '.php');
$file = File::createFileFromString(base_path('db/migrations'), $name, '.php');

$stub = File::readAndReplace(__DIR__.'../../../../../Stubs/migration.stub', [
'migration' => $name,
'table' => $this->argument('table'),
]);
$stub = File::readAndReplace(__DIR__.'../../../../../Stubs/migration.stub', [
'migration' => $name,
'table' => $this->argument('table'),
]);

File::write($file['file'], $stub);
File::write($file['file'], $stub);
}


$this->info('Model created successfully');

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}
Expand All @@ -30,7 +31,7 @@ public function handle()
$file = File::createFileFromString(base_path('db/seeders'), $name, '.php');

$stub = File::readAndReplace(__DIR__.'../../../../../Stubs/seeder.stub', [
'class' => $name
'class' => $name,
]);

File::write($file['file'], $stub);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Phenomine\Support\Console\Commands\Seeder;

use Phenomine\Contracts\Command\Command;
use Phenomine\Support\File;
use Phenomine\Support\Database\SeederRunner;

class RunSeederCommand extends Command
Expand All @@ -21,16 +20,17 @@ public function handle()
$result = $this->confirm('Do you want to continue?');
if (!$result) {
$this->warn('Operation cancelled.');

return;
}
}


$this->runner = new SeederRunner();

$seeders = $this->runner->getSeederFiles();
if (count($seeders) == 0) {
$this->info('Nothing to seed');

return true;
}
$counter = 0;
Expand Down
1 change: 1 addition & 0 deletions src/Phenomine/Support/Database/SeederRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function run($seeder)

$runner = new $seeder['class']();
$runner->run();

return [
'success' => true,
'status' => 'success',
Expand Down
Loading

0 comments on commit 582426a

Please sign in to comment.