Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kunicmarko20 authored Oct 4, 2018
1 parent b28d445 commit 6f2c138
Show file tree
Hide file tree
Showing 32 changed files with 292 additions and 862 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ License
This bundle is released under the MIT license. See the included
[LICENSE](LICENSE) file for more information.

## Testing
----------

The bundle is fully unit tested by [PHPUnit](https://www.phpunit.de/) with a code coverage close to **100%**. To
execute the test suite, check the travis [configuration](/.travis.yml).

## Contribute
-------------

Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
UPGRADE FROM 1.x to 2.0
=======================

Added typehints and return types.

Removed nullable constructor arguments on most services.

Classes are now final.

Marker exception is now an interface that implements throwable.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"sebastian/exporter": "<2.0.0"
},
"require-dev": {
"ext-json": "*",
"composer/composer": "^1.0",
"friendsofphp/php-cs-fixer": "^2.0",
"matthiasnoback/symfony-dependency-injection-test": "^1.0 || ^2.0",
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ parameters:
excludes_analyse:
- %currentWorkingDirectory%/src/Resources/views/Form/*html.php
- %currentWorkingDirectory%/tests/autoload.php
ignoreErrors:
- '#AbstractTestCase::getMock()#'
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<directory>./src/Resources</directory>
<directory>./tests</directory>
<directory>./vendor</directory>
<group>installation</group>
</exclude>
</whitelist>
</filter>
Expand Down
75 changes: 18 additions & 57 deletions src/Builder/JsonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace FOS\CKEditorBundle\Builder;

use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;

/**
Expand All @@ -23,76 +22,53 @@ final class JsonBuilder
/**
* @var PropertyAccessorInterface
*/
private $accessor;
private $propertyAccessor;

/**
* @var array
*/
private $values;
private $values = [];

/**
* @var array
*/
private $escapes;
private $escapes = [];

/**
* @var int
*/
private $jsonEncodeOptions;
private $jsonEncodeOptions = 0;

/**
* @param PropertyAccessorInterface|null $propertyAccessor
*/
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
public function __construct(PropertyAccessorInterface $propertyAccessor)
{
$this->accessor = $propertyAccessor ?: new PropertyAccessor();
$this->propertyAccessor = $propertyAccessor;

$this->reset();
}

/**
* @return int
*/
public function getJsonEncodeOptions()
public function getJsonEncodeOptions(): int
{
return $this->jsonEncodeOptions;
}

/**
* @param int $jsonEncodeOptions
*
* @return JsonBuilder
*/
public function setJsonEncodeOptions($jsonEncodeOptions)
public function setJsonEncodeOptions(int $jsonEncodeOptions): self
{
$this->jsonEncodeOptions = $jsonEncodeOptions;

return $this;
}

/**
* @return bool
*/
public function hasValues()
public function hasValues(): bool
{
return !empty($this->values);
}

/**
* @return array
*/
public function getValues()
public function getValues(): array
{
return $this->values;
}

/**
* @param array $values
* @param string $pathPrefix
*
* @return JsonBuilder
*/
public function setValues(array $values, $pathPrefix = null)
public function setValues(array $values, string $pathPrefix = null): self
{
foreach ($values as $key => $value) {
$path = sprintf('%s[%s]', $pathPrefix, $key);
Expand All @@ -108,16 +84,12 @@ public function setValues(array $values, $pathPrefix = null)
}

/**
* @param string $path
* @param mixed $value
* @param bool $escapeValue
*
* @return JsonBuilder
* @param mixed $value
*/
public function setValue($path, $value, $escapeValue = true)
public function setValue(string $path, $value, bool $escapeValue = true): self
{
if (!$escapeValue) {
$placeholder = uniqid('ivory', true);
$placeholder = uniqid('friendsofsymfony', true);
$this->escapes[sprintf('"%s"', $placeholder)] = $value;

$value = $placeholder;
Expand All @@ -128,22 +100,14 @@ public function setValue($path, $value, $escapeValue = true)
return $this;
}

/**
* @param string $path
*
* @return JsonBuilder
*/
public function removeValue($path)
public function removeValue(string $path): self
{
unset($this->values[$path], $this->escapes[$path]);

return $this;
}

/**
* @return JsonBuilder
*/
public function reset()
public function reset(): self
{
$this->values = [];
$this->escapes = [];
Expand All @@ -152,15 +116,12 @@ public function reset()
return $this;
}

/**
* @return string
*/
public function build()
public function build(): string
{
$json = [];

foreach ($this->values as $path => $value) {
$this->accessor->setValue($json, $path, $value);
$this->propertyAccessor->setValue($json, $path, $value);
}

return str_replace(
Expand Down
94 changes: 26 additions & 68 deletions src/Command/CKEditorInstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,14 @@ final class CKEditorInstallerCommand extends Command
*/
private $installer;

/**
* @param CKEditorInstaller|null $installer
*/
public function __construct(CKEditorInstaller $installer = null)
public function __construct(CKEditorInstaller $installer)
{
parent::__construct();

$this->installer = $installer ?: new CKEditorInstaller();
$this->installer = $installer;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('ckeditor:install')
Expand Down Expand Up @@ -102,10 +96,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$this->title($output);

Expand All @@ -118,13 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return mixed[]
*/
private function createOptions(InputInterface $input, OutputInterface $output)
private function createOptions(InputInterface $input, OutputInterface $output): array
{
$options = ['notifier' => $this->createNotifier($input, $output)];

Expand All @@ -151,13 +136,7 @@ private function createOptions(InputInterface $input, OutputInterface $output)
return array_filter($options);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return \Closure
*/
private function createNotifier(InputInterface $input, OutputInterface $output)
private function createNotifier(InputInterface $input, OutputInterface $output): \Closure
{
$clear = new ProgressBar($output);
$download = new ProgressBar($output);
Expand Down Expand Up @@ -255,10 +234,7 @@ private function createNotifier(InputInterface $input, OutputInterface $output)
};
}

/**
* @param OutputInterface $output
*/
private function title(OutputInterface $output)
private function title(OutputInterface $output): void
{
$output->writeln(
[
Expand All @@ -270,42 +246,28 @@ private function title(OutputInterface $output)
);
}

/**
* @param string|string[] $message
* @param OutputInterface $output
*/
private function comment($message, OutputInterface $output)
private function comment(string $message, OutputInterface $output): void
{
$output->writeln(' // '.$message);
$output->writeln('');
}

/**
* @param string $message
* @param OutputInterface $output
*/
private function success($message, OutputInterface $output)
private function success(string $message, OutputInterface $output): void
{
$this->block('[OK] - '.$message, $output, 'green', 'black');
}

/**
* @param string $message
* @param OutputInterface $output
*/
private function info($message, OutputInterface $output)
private function info(string $message, OutputInterface $output): void
{
$this->block('[INFO] - '.$message, $output, 'yellow', 'black');
}

/**
* @param string $message
* @param OutputInterface $output
* @param string $background
* @param string $font
*/
private function block($message, OutputInterface $output, $background = null, $font = null)
{
private function block(
string $message,
OutputInterface $output,
string $background = null,
string $font = null
): void {
$options = [];

if (null !== $background) {
Expand All @@ -328,16 +290,16 @@ private function block($message, OutputInterface $output, $background = null, $f
}

/**
* @param string|string[] $question
* @param string[] $choices
* @param string $default
* @param InputInterface $input
* @param OutputInterface $output
*
* @return string|null
* @param string[] $question
* @param string[] $choices
*/
private function choice($question, array $choices, $default, InputInterface $input, OutputInterface $output)
{
private function choice(
array $question,
array $choices,
string $default,
InputInterface $input,
OutputInterface $output
): ?string {
$helper = new QuestionHelper();

if (is_array($question)) {
Expand All @@ -355,11 +317,7 @@ private function choice($question, array $choices, $default, InputInterface $inp
return $result;
}

/**
* @param ProgressBar $progress
* @param OutputInterface $output
*/
private function finishProgressBar($progress, OutputInterface $output)
private function finishProgressBar(ProgressBar $progress, OutputInterface $output): void
{
$progress->finish();
$output->writeln(['', '']);
Expand Down
2 changes: 1 addition & 1 deletion src/Config/CKEditorConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private function resolveConfigs(array $config): array
return $config;
}

private function resolveStylesSet(array $config)
private function resolveStylesSet(array $config): array
{
if (empty($config['styles'])) {
return $config;
Expand Down
Loading

0 comments on commit 6f2c138

Please sign in to comment.