Skip to content

Commit 2afbdcb

Browse files
committed
=Fixes multiple bugs in the html. Improves html template and validation rules. Switches to a PSR-2 coding style.
1 parent 352537e commit 2afbdcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+949
-1932
lines changed

config/.php_cs.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"5.6.24","version":"2.1.2:","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":["property"],"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true},"hashes":{"codegenerator.php":570438976}}

src/.php_cs.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"5.6.24","version":"2.1.2:","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":["property"],"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true},"hashes":{"CodeGeneratorServiceProvider.php":-1685777146}}

src/CodeGeneratorServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function register()
7272
*/
7373
protected function createDirectory($path, $mode = '0777')
7474
{
75-
if(!file_exists($path))
76-
{
75+
if (!file_exists($path)) {
7776
mkdir($path, $mode);
7877
}
7978
}

src/Commands/.php_cs.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"5.6.24","version":"2.1.2:","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":["property"],"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true},"hashes":{"CreateControllerCommand.php":1979890676,"CreateCreateViewCommand.php":131691758,"CreateEditViewCommand.php":1171483022,"CreateFieldsFileCommand.php":1361178139,"CreateFormRequestCommand.php":194589446,"CreateFormViewCommand.php":623765643,"CreateIndexViewCommand.php":-1734787902,"CreateLanguageCommand.php":-1844147042,"CreateLayoutCommand.php":396331127,"CreateMigrationCommand.php":1405553898,"CreateModelCommand.php":-1793560043,"CreateResourcesCommand.php":-1298335991,"CreateRoutesCommand.php":1075556265,"CreateShowViewCommand.php":2103655095,"CreateViewLayoutCommand.php":213476386,"CreateViewsCommand.php":-986690200}}

src/Commands/CreateControllerCommand.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CreateControllerCommand extends GeneratorCommand
5151
*/
5252
protected function getStub()
5353
{
54-
return $this->getStubByName('controller', $this->getTemplateName() );
54+
return $this->getStubByName('controller', $this->getTemplateName());
5555
}
5656

5757
/**
@@ -68,8 +68,7 @@ protected function buildClass($name)
6868

6969
$formRequestName = 'Request';
7070

71-
if($input->formRequest)
72-
{
71+
if ($input->formRequest) {
7372
$stub = $this->getStubContent('controller-with-form-request', $input->template);
7473
$formRequestName = $input->formRequestName;
7574
$this->makeFormRequest($input);
@@ -100,8 +99,7 @@ protected function buildClass($name)
10099
*/
101100
protected function getUploadFileMethod(array $fields)
102101
{
103-
if($this->isContainfile($fields))
104-
{
102+
if ($this->isContainfile($fields)) {
105103
return $this->getStubContent('controller-upload-method', $this->getTemplateName());
106104
}
107105

@@ -129,7 +127,7 @@ protected function getRequestsNamespace()
129127
*/
130128
protected function isContainMultipleAnswers(array $fields)
131129
{
132-
$filtered = array_filter($fields, function($field){
130+
$filtered = array_filter($fields, function ($field) {
133131
return $field->isMultipleAnswers;
134132
});
135133

@@ -145,7 +143,7 @@ protected function isContainMultipleAnswers(array $fields)
145143
*/
146144
protected function makeFormRequest($input)
147145
{
148-
$this->callSilent('create:form-request',
146+
$this->callSilent('create:form-request',
149147
[
150148
'class-name' => $input->formRequestName,
151149
'--fields' => $input->fields,
@@ -169,7 +167,7 @@ protected function getModelFullName($path, $name)
169167
{
170168
$final = !empty($path) ? $this->getModelsPath() . Helpers::getPathWithSlash($path) : $this->getModelsPath();
171169

172-
return Helpers::convertSlashToBackslash($final . ucfirst($name));
170+
return Helpers::convertSlashToBackslash($final . $name);
173171
}
174172

175173
/**
@@ -180,7 +178,9 @@ protected function getModelFullName($path, $name)
180178
protected function getCommandInput()
181179
{
182180
$controllerName = trim($this->argument('controller-name'));
183-
$modelName = strtolower(trim($this->option('model-name')) ?: str_singular(Helpers::removePostFixWith($controllerName, 'Controller')));
181+
$plainControllerName = str_singular(Helpers::removePostFixWith($controllerName, 'Controller'));
182+
183+
$modelName = trim($this->option('model-name')) ?: $plainControllerName;
184184
$viewDirectory = trim($this->option('views-directory'));
185185
$prefix = trim($this->option('routes-prefix'));
186186
$perPage = intval($this->option('models-per-page'));
@@ -190,11 +190,11 @@ protected function getCommandInput()
190190
$formRequest = $this->option('with-form-request');
191191
$force = $this->option('force');
192192
$modelDirectory = trim($this->option('model-directory'));
193-
$formRequestName = ucfirst($modelName) . 'FormRequest';
193+
$formRequestName = $plainControllerName . 'FormRequest';
194194
$template = $this->getTemplateName();
195195

196-
return (object) compact('viewDirectory','viewName','modelName','prefix','perPage','fileSnippet','modelDirectory',
197-
'langFile','fields','formRequest','formRequestName','force','fieldsFile','template');
196+
return (object) compact('viewDirectory', 'viewName', 'modelName', 'prefix', 'perPage', 'fileSnippet', 'modelDirectory',
197+
'langFile', 'fields', 'formRequest', 'formRequestName', 'force', 'fieldsFile', 'template');
198198
}
199199

200200
/**
@@ -328,8 +328,7 @@ public function getNameInput()
328328
$path = $this->getControllersPath();
329329
$directory = trim($this->option('controller-directory'));
330330

331-
if(!empty($directory))
332-
{
331+
if (!empty($directory)) {
333332
$path .= Helpers::getPathWithSlash($directory);
334333
}
335334

@@ -347,16 +346,13 @@ protected function getFileReadySnippet(array $fields)
347346
{
348347
$code = '';
349348

350-
foreach($fields as $field)
351-
{
352-
if($field->isFile())
353-
{
349+
foreach ($fields as $field) {
350+
if ($field->isFile()) {
354351
$code = ($code) ?: '$this';
355352
$code .= sprintf("->uploadFile('%s', \$data)", $field->name);
356353
}
357354
}
358355

359356
return $code != '' ? $code . ';' : $code;
360357
}
361-
362358
}

src/Commands/CreateCreateViewCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,13 @@ protected function handleCreateView()
5252
$fields = $this->getFields($input->fields, $input->languageFileName, $input->fieldsFile);
5353
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'create');
5454

55-
if($this->canCreateView($destenationFile, $input->force))
56-
{
55+
if ($this->canCreateView($destenationFile, $input->force)) {
5756
$this->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
5857
->createMissingViews($input)
5958
->replaceCommonTemplates($stub, $input)
6059
->replaceFileUpload($stub, $fields)
6160
->createViewFile($stub, $destenationFile)
6261
->info('Create view was crafted successfully.');
6362
}
64-
6563
}
66-
6764
}

src/Commands/CreateEditViewCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ protected function handleCreateView()
5252
$fields = $this->getFields($input->fields, $input->languageFileName, $input->fieldsFile);
5353
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'edit');
5454

55-
if($this->canCreateView($destenationFile, $input->force, $fields))
56-
{
55+
if ($this->canCreateView($destenationFile, $input->force, $fields)) {
5756
$this->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
5857
->createMissingViews($input)
5958
->replaceCommonTemplates($stub, $input)
@@ -64,6 +63,4 @@ protected function handleCreateView()
6463
->info('Edit view view was crafted successfully.');
6564
}
6665
}
67-
68-
6966
}

src/Commands/CreateFieldsFileCommand.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ class CreateFieldsFileCommand extends Command
4747
*/
4848
public function handle()
4949
{
50-
if(File::exists($this->getDestinationFullname()) && !$this->isForce())
51-
{
52-
throw new Exception('The file ' . $this->getFilename() . ' already exists. To override it try passing the --force option to override it.' );
50+
if (File::exists($this->getDestinationFullname()) && !$this->isForce()) {
51+
throw new Exception('The file ' . $this->getFilename() . ' already exists. To override it try passing the --force option to override it.');
5352
}
5453

55-
if(!$this->createFile($this->getDestinationFullname(), $this->getFieldAsJson()))
56-
{
54+
if (!$this->createFile($this->getDestinationFullname(), $this->getFieldAsJson())) {
5755
throw new Exception('Something went wrong while trying to create the fields file.');
5856
}
5957

@@ -68,7 +66,7 @@ public function handle()
6866
*/
6967
protected function getFieldAsJson()
7068
{
71-
$fields = array_map(function($field){
69+
$fields = array_map(function ($field) {
7270
return $field->toArray();
7371
}, $this->getFields());
7472

@@ -109,8 +107,7 @@ protected function getFields()
109107
{
110108
$driver = strtolower(DB::getDriverName());
111109

112-
if(!in_array($driver, $this->drivers))
113-
{
110+
if (!in_array($driver, $this->drivers)) {
114111
throw new Exception('The database driver user is not supported!');
115112
}
116113

src/Commands/CreateFormRequestCommand.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class CreateFormRequestCommand extends Command
2424
{--template-name= : The template name to use when generating the code.}
2525
{--force : This option will override the form-request if one already exists.}';
2626

27-
2827
/**
2928
* The console command description.
3029
*
@@ -72,15 +71,13 @@ protected function makeFile($fileFullname, $stub, $force = false)
7271
{
7372
$this->createDirectory(dirname($fileFullname));
7473

75-
if(File::exists($fileFullname) && !$force)
76-
{
74+
if (File::exists($fileFullname) && !$force) {
7775
throw new Exception('There is a form-request class with the same name! To override existing file try passing "--force" command');
7876
}
7977

80-
if(! File::put($fileFullname, $stub))
81-
{
78+
if (! File::put($fileFullname, $stub)) {
8279
throw new Exception('New form-request have been created');
83-
}
80+
}
8481

8582
$this->error('The form-request failed to create');
8683

@@ -100,7 +97,7 @@ protected function getCommandInput()
10097
$force = $this->option('force');
10198
$template = $this->option('template-name');
10299

103-
return (object) compact('fileName','fields','fieldsFile','force','template');
100+
return (object) compact('fileName', 'fields', 'fieldsFile', 'force', 'template');
104101
}
105102

106103
/**

src/Commands/CreateFormViewCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ public function __construct()
4848
*/
4949
protected function handleCreateView()
5050
{
51-
5251
$input = $this->getCommandInput();
5352
$stub = $this->getStubContent($this->stubName);
5453
$fields = $this->getFields($input->fields, $input->languageFileName, $input->fieldsFile);
5554
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'form');
56-
$htmlCreator = $this->getHtmlGenerator($fields, $input->modelName ,$this->getTemplateName());
55+
$htmlCreator = $this->getHtmlGenerator($fields, $input->modelName, $this->getTemplateName());
5756

58-
if($this->canCreateView($destenationFile, $input->force))
59-
{
57+
if ($this->canCreateView($destenationFile, $input->force)) {
6058
$this->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
6159
->replaceCommonTemplates($stub, $input)
6260
->replaceFields($stub, $htmlCreator->getHtmlFields())
@@ -79,5 +77,4 @@ protected function replaceFields(&$stub, $fields)
7977

8078
return $this;
8179
}
82-
8380
}

0 commit comments

Comments
 (0)