Skip to content

Commit

Permalink
Code: add types
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Nov 17, 2023
1 parent 8e2920c commit 756ee57
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 454 deletions.
2 changes: 1 addition & 1 deletion ruleset.xml
Expand Up @@ -16,5 +16,5 @@
</rule>

<!-- Excludes -->
<exclude-pattern>/tests/tmp</exclude-pattern>
<exclude-pattern>/tests</exclude-pattern>
</ruleset>
34 changes: 0 additions & 34 deletions src/Facebook/ActivityFeed/ActivityFeed.php

This file was deleted.

52 changes: 8 additions & 44 deletions src/Facebook/Attributes.php
Expand Up @@ -18,22 +18,14 @@ class Attributes implements Countable, ArrayAccess, IteratorAggregate
{

/** @var array<string, mixed> */
private $attrs = [];
private array $attrs = [];

/** GETTERS/SETTERS *******************************************************/

/**
* @param mixed $value
*/
public function add(string $name, $value): void
public function add(string $name, mixed $value): void
{
$this->attrs[$name] = $value;
}

/**
* @param mixed $value
*/
public function data(string $name, $value): void
public function data(string $name, mixed $value): void
{
$this->attrs['data-' . $name] = $value;
}
Expand All @@ -54,68 +46,40 @@ public function setAttributes(array $attrs): void
$this->attrs = $attrs;
}

/** COUNTABLE *************************************************************/

public function count(): int
{
return count($this->attrs);
}

/** ARRAY ACCESS **********************************************************/

/**
* @param mixed $offset
*/
public function offsetExists($offset): bool
public function offsetExists(mixed $offset): bool
{
return isset($this->attrs[$offset]);
}

/**
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
public function offsetGet(mixed $offset): mixed
{
return $this->attrs[$offset];
}

/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value): void
public function offsetSet(mixed $offset, mixed $value): void
{
$this->attrs[$offset] = $value;
}

/**
* @param mixed $offset
*/
public function offsetUnset($offset): void
public function offsetUnset(mixed $offset): void
{
unset($this->attrs[$offset]);
}

/** ARRAY ACCESS **********************************************************/

/**
* @todo remove phpcsSuppress after upgrade to slevomat/coding-standard 6
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation
* @return ArrayIterator<string, mixed>
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->attrs);
}

/** MAGIC *****************************************************************/

/**
* @param mixed $name
* @return mixed
*/
public function __get($name)
public function __get(string $name): mixed
{
if ($this->offsetExists($name)) {
return $this->offsetGet($name);
Expand Down
8 changes: 0 additions & 8 deletions src/Facebook/Comments/Comments.php
Expand Up @@ -5,25 +5,17 @@
use Contributte\Social\Facebook\Control;
use Nette\Utils\Html;

/**
* Comments control
*/
class Comments extends Control
{

/** Shemes */
public const SCHEME_LIGHT = 'light';
public const SCHEME_DARK = 'dark';

/** API *******************************************************************/

public function build(): Html
{
return $this->createElement($this->attributes);
}

/** RENDERS ***************************************************************/

public function render(): void
{
echo $this->build();
Expand Down
13 changes: 3 additions & 10 deletions src/Facebook/Control.php
Expand Up @@ -14,27 +14,24 @@
abstract class Control extends NetteControl
{

/** @var Attributes */
protected $attributes;
protected Attributes $attributes;

public function __construct()
{
$this->attributes = new Attributes();
}

/** GETTERS ***************************************************************/
abstract public function build(): Html;

public function getAttributes(): Attributes
{
return $this->attributes;
}

/** HELPERS ***************************************************************/

/**
* @param Attributes|array<string, string> $attributes
*/
protected function createElement($attributes): Html
protected function createElement(Attributes|array $attributes): Html
{
$el = Html::el('div');

Expand All @@ -45,8 +42,4 @@ protected function createElement($attributes): Html
return $el;
}

/** ABSTRACT **************************************************************/

abstract public function build(): Html;

}
7 changes: 0 additions & 7 deletions src/Facebook/EmbeddedPosts/EmbeddedPosts.php
Expand Up @@ -5,21 +5,14 @@
use Contributte\Social\Facebook\Control;
use Nette\Utils\Html;

/**
* EmbeddedPosts control
*/
class EmbeddedPosts extends Control
{

/** API *******************************************************************/

public function build(): Html
{
return $this->createElement($this->attributes);
}

/** RENDERS ***************************************************************/

public function render(): void
{
echo $this->build();
Expand Down
7 changes: 0 additions & 7 deletions src/Facebook/EmbeddedVideos/EmbeddedVideos.php
Expand Up @@ -5,21 +5,14 @@
use Contributte\Social\Facebook\Control;
use Nette\Utils\Html;

/**
* EmbeddedVideos control
*/
class EmbeddedVideos extends Control
{

/** API *******************************************************************/

public function build(): Html
{
return $this->createElement($this->attributes);
}

/** RENDERS ***************************************************************/

public function render(): void
{
echo $this->build();
Expand Down
39 changes: 0 additions & 39 deletions src/Facebook/Facepile/Facepile.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Facebook/FollowButton/FollowButton.php
Expand Up @@ -5,31 +5,22 @@
use Contributte\Social\Facebook\Control;
use Nette\Utils\Html;

/**
* FollowButton control
*/
class FollowButton extends Control
{

/** Layouts */
public const LAYOUT_STANDARD = 'standard';
public const LAYOUT_BOX_COUNT = 'box_count';
public const LAYOUT_BUTTON_COUNT = 'button_count';
public const LAYOUT_BUTTON = 'button';

/** Shemes */
public const SCHEME_LIGHT = 'light';
public const SCHEME_DARK = 'dark';

/** API *******************************************************************/

public function build(): Html
{
return $this->createElement($this->attributes);
}

/** RENDERS ***************************************************************/

public function render(): void
{
echo $this->build();
Expand Down
34 changes: 0 additions & 34 deletions src/Facebook/LikeBox/LikeBox.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Facebook/LikeButton/LikeButton.php
Expand Up @@ -5,31 +5,22 @@
use Contributte\Social\Facebook\Control;
use Nette\Utils\Html;

/**
* LikeButton control
*/
class LikeButton extends Control
{

/** Layouts */
public const LAYOUT_STANDARD = 'standard';
public const LAYOUT_BOX_COUNT = 'box_count';
public const LAYOUT_BUTTON_COUNT = 'button_count';
public const LAYOUT_BUTTON = 'button';

/** Actions */
public const ACTION_LIKE = 'like';
public const ACTION_RECOMMEND = 'recommend';

/** API *******************************************************************/

public function build(): Html
{
return $this->createElement($this->attributes);
}

/** RENDERS ***************************************************************/

public function render(): void
{
echo $this->build();
Expand Down

0 comments on commit 756ee57

Please sign in to comment.