Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Apr 17, 2023
1 parent 2ef31eb commit f66d4b4
Show file tree
Hide file tree
Showing 25 changed files with 42 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/Elements/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace TypiCMS\Form\Elements;

use DateTime;

class Date extends Text
{
protected array $attributes = [
Expand All @@ -10,7 +12,7 @@ class Date extends Text

public function value(mixed $value): Input
{
if ($value instanceof \DateTime) {
if ($value instanceof DateTime) {
$value = $value->format('Y-m-d');
}

Expand All @@ -20,7 +22,7 @@ public function value(mixed $value): Input
public function defaultValue(mixed $value): self
{
if (!$this->hasValue()) {
if ($value instanceof \DateTime) {
if ($value instanceof DateTime) {
$value = $value->format('Y-m-d');
}
$this->setValue($value);
Expand Down
6 changes: 4 additions & 2 deletions src/Elements/DateTimeLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace TypiCMS\Form\Elements;

use DateTime;

class DateTimeLocal extends Text
{
protected array $attributes = [
Expand All @@ -10,7 +12,7 @@ class DateTimeLocal extends Text

public function value(mixed $value): Input
{
if ($value instanceof \DateTime) {
if ($value instanceof DateTime) {
$value = $value->format('Y-m-d\TH:i');
}

Expand All @@ -20,7 +22,7 @@ public function value(mixed $value): Input
public function defaultValue(mixed $value): self
{
if (!$this->hasValue()) {
if ($value instanceof \DateTime) {
if ($value instanceof DateTime) {
$value = $value->format('Y-m-d\TH:i');
}
$this->setValue($value);
Expand Down
8 changes: 4 additions & 4 deletions src/Elements/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function data(array|string $attribute, mixed $value = null): self
{
if (is_array($attribute)) {
foreach ($attribute as $key => $val) {
$this->setAttribute('data-'.$key, $val);
$this->setAttribute('data-' . $key, $val);
}
} else {
$this->setAttribute('data-'.$attribute, $value);
$this->setAttribute('data-' . $attribute, $value);
}

return $this;
Expand All @@ -59,7 +59,7 @@ public function clear(string $attribute): self
public function addClass(string $class): self
{
if (isset($this->attributes['class'])) {
$class = $this->attributes['class'].' '.$class;
$class = $this->attributes['class'] . ' ' . $class;
}

$this->setAttribute('class', $class);
Expand Down Expand Up @@ -106,7 +106,7 @@ public function __toString(): string

protected function renderAttributes(): string
{
list($attributes, $values) = $this->splitKeysAndValues($this->attributes);
[$attributes, $values] = $this->splitKeysAndValues($this->attributes);

return implode(array_map(function ($attribute, $value) {
return sprintf(' %s="%s"', $attribute, $this->escape($value));
Expand Down
4 changes: 2 additions & 2 deletions src/Elements/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function render(): string

protected function renderOptions(): string
{
list($values, $labels) = $this->splitKeysAndValues($this->options);
[$values, $labels] = $this->splitKeysAndValues($this->options);

$tags = array_map(function ($value, $label) {
if (is_array($label)) {
Expand All @@ -59,7 +59,7 @@ protected function renderOptions(): string

protected function renderOptGroup(string $label, array $options): string
{
list($values, $labels) = $this->splitKeysAndValues($options);
[$values, $labels] = $this->splitKeysAndValues($options);

$options = array_map(function ($value, $label) {
return $this->renderOption($value, $label);
Expand Down
6 changes: 4 additions & 2 deletions tests/BindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace TypiCMS\Form\Tests;

use DateTime;
use Mockery;
use PHPUnit\Framework\TestCase;
use stdClass;
use TypiCMS\Form\FormBuilder;

/**
* @internal
*
* @coversNothing
*/
class BindingTest extends TestCase
Expand Down Expand Up @@ -461,8 +463,8 @@ private function getStubObject()
$obj->email = '[email protected]';
$obj->first_name = 'John';
$obj->last_name = 'Doe';
$obj->date_of_birth = new \DateTime('1985-05-06');
$obj->date_and_time_of_birth = new \DateTime('1985-05-06 16:39');
$obj->date_of_birth = new DateTime('1985-05-06');
$obj->date_and_time_of_birth = new DateTime('1985-05-06 16:39');
$obj->gender = 'male';
$obj->terms = 'agree';
$obj->color = 'green';
Expand Down
1 change: 1 addition & 0 deletions tests/ButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class ButtonTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/CheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class CheckboxTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @internal
*
* @coversNothing
*/
class DateTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/DateTimeLocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @internal
*
* @coversNothing
*/
class DateTimeLocalTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class EmailTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class FileTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/FormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @internal
*
* @coversNothing
*/
class FormBuilderTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/FormOpenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class FormOpenTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/HiddenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class HiddenTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/IlluminateErrorStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* @internal
*
* @coversNothing
*/
class IlluminateErrorStoreTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/InputContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract protected function getTestSubjectType();

protected function elementRegExp($attributes)
{
return '/\A<input type="'.$this->getTestSubjectType().'" .*?'.$attributes.'( .*?|)>\z/';
return '/\A<input type="' . $this->getTestSubjectType() . '" .*?' . $attributes . '( .*?|)>\z/';
}

public function testTextCanBeCreated()
Expand Down
1 change: 1 addition & 0 deletions tests/LabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @internal
*
* @coversNothing
*/
class LabelTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/NumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class NumberTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/OldInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @internal
*
* @coversNothing
*/
class OldInputTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/PasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class PasswordTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/RadioButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class RadioButtonTest extends TestCase
Expand Down
3 changes: 2 additions & 1 deletion tests/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class SelectTest extends TestCase
Expand All @@ -24,7 +25,7 @@ protected function getTestSubjectType()

protected function elementRegExp($attributes)
{
return '/\A<select .*?'.$attributes.'( .*?|)><\/select>\z/';
return '/\A<select .*?' . $attributes . '( .*?|)><\/select>\z/';
}

public function testSelectCanBeCreatedWithOptions()
Expand Down
3 changes: 2 additions & 1 deletion tests/TextAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class TextAreaTest extends TestCase
Expand All @@ -24,7 +25,7 @@ protected function getTestSubjectType()

protected function elementRegExp($attributes)
{
return '/\A<textarea .*?'.$attributes.'( .*?|)><\/textarea>\z/';
return '/\A<textarea .*?' . $attributes . '( .*?|)><\/textarea>\z/';
}

public function testRenderBasicTextArea()
Expand Down
6 changes: 3 additions & 3 deletions tests/TextSubclassContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public function testDefaultValue()
{
$text = $this->newTestSubjectInstance('email');

$expected = '<input type="'.$this->getTestSubjectType().'" name="email" value="[email protected]">';
$expected = '<input type="' . $this->getTestSubjectType() . '" name="email" value="[email protected]">';
$result = $text->defaultValue('[email protected]')->render();
$this->assertEquals($expected, $result);

$text = $this->newTestSubjectInstance('email');

$expected = '<input type="'.$this->getTestSubjectType().'" name="email" value="[email protected]">';
$expected = '<input type="' . $this->getTestSubjectType() . '" name="email" value="[email protected]">';
$result = $text->value('[email protected]')->defaultValue('[email protected]')->render();
$this->assertEquals($expected, $result);

$text = $this->newTestSubjectInstance('email');

$expected = '<input type="'.$this->getTestSubjectType().'" name="email" value="[email protected]">';
$expected = '<input type="' . $this->getTestSubjectType() . '" name="email" value="[email protected]">';
$result = $text->defaultValue('[email protected]')->value('[email protected]')->render();
$this->assertEquals($expected, $result);
}
Expand Down
1 change: 1 addition & 0 deletions tests/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @internal
*
* @coversNothing
*/
class TextTest extends TestCase
Expand Down

0 comments on commit f66d4b4

Please sign in to comment.