Skip to content

Commit

Permalink
Merge pull request #38 from bolt/fix/ex-json-and-code-style
Browse files Browse the repository at this point in the history
Fix `ext-json` and run CS fixer
  • Loading branch information
I-Valchev authored Dec 2, 2020
2 parents cb4e5f5 + 7d5099a commit 448c5f7
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 220 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
}
],
"require": {
"php": ">=7.2.2",
"php": ">=7.2.9",
"twig/twig": "^2.12 | ^3.0",
"ext/json": "*"
"ext-json": "*"
},
"require-dev": {
"bolt/core": "^4.0.0",
"symplify/easy-coding-standard": "^6.0"
"bolt/core": "^4.1",
"symplify/easy-coding-standard": "^8.3"
},
"autoload": {
"psr-4": {
Expand Down
101 changes: 0 additions & 101 deletions easy-coding-standard.yml

This file was deleted.

151 changes: 151 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer;
use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer;
use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer;
use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\Fixer\Basic\Psr0Fixer;
use PhpCsFixer\Fixer\Basic\Psr4Fixer;
use PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer;
use PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer;
use PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer;
use PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer;
use PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer;
use PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer;
use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer;
use PhpCsFixer\Fixer\Operator\IncrementStyleFixer;
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
use PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer;
use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer;
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer;
use PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer;
use SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
use Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousDocBlockWhitespaceFixer;
use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set('sets', ['clean-code', 'common', 'php70', 'php71', 'psr12', 'symfony', 'symfony-risky']);

$parameters->set('paths', [
__DIR__ . '/src',
__DIR__ . '/ecs.php',
]);

$parameters->set('cache_directory', 'var/cache/ecs');

$parameters->set('skip', [
OrderedClassElementsFixer::class => null,
YodaStyleFixer::class => null,
IncrementStyleFixer::class => null,
PhpdocAnnotationWithoutDotFixer::class => null,
PhpdocSummaryFixer::class => null,
PhpdocAlignFixer::class => null,
NativeConstantInvocationFixer::class => null,
NativeFunctionInvocationFixer::class => null,
UnaryOperatorSpacesFixer::class => null,
ArrayOpenerAndCloserNewlineFixer::class => null,
ArrayListItemNewlineFixer::class => null,
]);

$services = $containerConfigurator->services();

$services->set(StandaloneLineInMultilineArrayFixer::class);

$services->set(BlankLineAfterStrictTypesFixer::class);

$services->set(ConcatSpaceFixer::class)
->call('configure', [['spacing' => 'one']]);

$services->set(RemoveSuperfluousDocBlockWhitespaceFixer::class);

$services->set(PhpUnitMethodCasingFixer::class);

$services->set(FinalInternalClassFixer::class);

$services->set(MbStrFunctionsFixer::class);

$services->set(Psr0Fixer::class);

$services->set(Psr4Fixer::class);

$services->set(LowercaseCastFixer::class);

$services->set(ShortScalarCastFixer::class);

$services->set(BlankLineAfterOpeningTagFixer::class);

$services->set(NoLeadingImportSlashFixer::class);

$services->set(OrderedImportsFixer::class)
->call('configure', [[
'importsOrder' => ['class', 'const', 'function'],
]]);

$services->set(DeclareEqualNormalizeFixer::class)
->call('configure', [['space' => 'none']]);

$services->set(NewWithBracesFixer::class);

$services->set(BracesFixer::class)
->call('configure', [[
'allow_single_line_closure' => false,
'position_after_functions_and_oop_constructs' => 'next',
'position_after_control_structures' => 'same',
'position_after_anonymous_constructs' => 'same',
]]);

$services->set(NoBlankLinesAfterClassOpeningFixer::class);

$services->set(VisibilityRequiredFixer::class)
->call('configure', [[
'elements' => ['const', 'method', 'property'],
]]);

$services->set(TernaryOperatorSpacesFixer::class);

$services->set(ReturnTypeDeclarationFixer::class);

$services->set(NoTrailingWhitespaceFixer::class);

$services->set(NoSinglelineWhitespaceBeforeSemicolonsFixer::class);

$services->set(NoWhitespaceBeforeCommaInArrayFixer::class);

$services->set(WhitespaceAfterCommaInArrayFixer::class);

$services->set(PhpdocToReturnTypeFixer::class);

$services->set(FullyQualifiedStrictTypesFixer::class);

$services->set(NoSuperfluousPhpdocTagsFixer::class);

$services->set(PhpdocLineSpanFixer::class)
->call('configure', [['property' => 'single']]);

$services->set(DisallowYodaComparisonSniff::class);
};
2 changes: 2 additions & 0 deletions src/CaptchaException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Bolt\BoltForms;

class CaptchaException extends \Exception
Expand Down
10 changes: 5 additions & 5 deletions src/Event/BoltFormsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Gawain Lynch <[email protected]>
* @author Gawain Lynch <[email protected]>
* @copyright Copyright (c) 2014-2016, Gawain Lynch
* @license http://opensource.org/licenses/GPL-3.0 GNU Public License 3.0
* @license http://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License 3.0
* @license http://opensource.org/licenses/GPL-3.0 GNU Public License 3.0
* @license http://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License 3.0
*/
class BoltFormsEvent extends FormEvent
{
Expand Down
10 changes: 5 additions & 5 deletions src/Event/BoltFormsEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Gawain Lynch <[email protected]>
* @author Gawain Lynch <[email protected]>
* @copyright Copyright (c) 2014-2016, Gawain Lynch
* @license http://opensource.org/licenses/GPL-3.0 GNU Public License 3.0
* @license http://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License 3.0
* @license http://opensource.org/licenses/GPL-3.0 GNU Public License 3.0
* @license http://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License 3.0
*/
final class BoltFormsEvents
{
Expand Down
3 changes: 2 additions & 1 deletion src/EventSubscriber/ContentTypePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function save(PostSubmitEvent $event, Form $form, Collection $config): vo
}

if (! $this->boltConfig->getContentType($config->get('name', ''))) {
return; // todo: handle this error message better
// todo: handle this error message better
return;
}

$content = new Content();
Expand Down
3 changes: 2 additions & 1 deletion src/EventSubscriber/DbTablePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function save(PostSubmitEvent $event, Form $form, Collection $config): vo
}

if (! $config->get('name', '')) {
return; // todo: handle this error message better
// todo: handle this error message better
return;
}

$table = $config->get('name', '');
Expand Down
14 changes: 9 additions & 5 deletions src/EventSubscriber/FileUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function processFileField(Form $field, Collection $fieldConfig, PostSubm

$filename = $this->getFilename($field->getName(), $form, $formConfig);
$path = $fieldConfig['directory'] ?? '/uploads/';
Str::ensureStartsWith($path, DIRECTORY_SEPARATOR);
Str::ensureStartsWith($path, \DIRECTORY_SEPARATOR);
$files = $this->uploadFiles($filename, $file, $path);

if (isset($fieldConfig['attach']) && $fieldConfig['attach']) {
Expand All @@ -62,7 +62,7 @@ private function processFileField(Form $field, Collection $fieldConfig, PostSubm

private function getFilename(string $fieldname, Form $form, Collection $formConfig): string
{
$filenameFormat = $formConfig->get('fields')[$fieldname]['file_format'] ?? 'Uploaded file'.uniqid();
$filenameFormat = $formConfig->get('fields')[$fieldname]['file_format'] ?? 'Uploaded file' . uniqid();
$filename = $this->helper->get($filenameFormat, $form);

if (! $filename) {
Expand All @@ -77,7 +77,7 @@ private function getFilename(string $fieldname, Form $form, Collection $formConf
*/
private function uploadFiles(string $filename, $file, string $path = ''): array
{
$uploadPath = $this->projectDir.$path;
$uploadPath = $this->projectDir . $path;
$uploadHandler = new Handler($uploadPath, [
Handler::OPTION_AUTOCONFIRM => true,
Handler::OPTION_OVERWRITE => false,
Expand Down Expand Up @@ -113,8 +113,12 @@ private function uploadFiles(string $filename, $file, string $path = ''): array

private function sanitiseFilename(string $filename): string
{
$extensionSlug = new Slugify(['regexp' => '/([^a-z0-9]|-)+/']);
$filenameSlug = new Slugify(['lowercase' => false]);
$extensionSlug = new Slugify([
'regexp' => '/([^a-z0-9]|-)+/',
]);
$filenameSlug = new Slugify([
'lowercase' => false,
]);

$extension = $extensionSlug->slugify(Path::getExtension($filename));
$filename = $filenameSlug->slugify(Path::getFilenameWithoutExtension($filename));
Expand Down
3 changes: 2 additions & 1 deletion src/EventSubscriber/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function mail(): void
'[Boltforms] Form {formname} sent email to {recipient}',
[
'formname' => $this->event->getFormName(),
'recipient' => (string) $email->getTo()[0]->getName(), // is this casting right?
// is this casting right?
'recipient' => (string) $email->getTo()[0]->getName(),
]
);
}
Expand Down
Loading

0 comments on commit 448c5f7

Please sign in to comment.