Skip to content

Commit

Permalink
Method return and argument types added #212
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Mar 10, 2022
1 parent f565c3b commit 6e76b35
Show file tree
Hide file tree
Showing 23 changed files with 481 additions and 474 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [UNRELEASED]
### Fixed
- NaN
- PHP dependency updated to support php v8.0 #212 #214 (thanks @freescout-helpdesk)
- Method return and argument types added

### Added
- NaN
Expand All @@ -15,7 +16,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- NaN

### Breaking changes
- NaN
- No longer supports php >=5.5.9 but instead requires at least php v7.0.0


## [3.2.0] - 2022-03-07
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": ">=5.5.9",
"php": ">=7.0.0",
"ext-openssl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
6 changes: 3 additions & 3 deletions src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($object) {
* @return string
*/
public function __toString() {
return $this->full ? $this->full : "";
return $this->full ?: "";
}

/**
Expand All @@ -75,7 +75,7 @@ public function __serialize(){
*
* @return array
*/
public function toArray(){
public function toArray(): array {
return $this->__serialize();
}

Expand All @@ -84,7 +84,7 @@ public function toArray(){
*
* @return string
*/
public function toString(){
public function toString(): string {
return $this->__toString();
}
}
18 changes: 10 additions & 8 deletions src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function __construct(Message $oMessage, Part $part) {
* @return mixed
* @throws MethodNotFoundException
*/
public function __call($method, $arguments) {
public function __call(string $method, array $arguments) {
if(strtolower(substr($method, 0, 3)) === 'get') {
$name = Str::snake(substr($method, 3));

Expand Down Expand Up @@ -242,8 +242,8 @@ protected function fetch() {
*
* @return boolean
*/
public function save($path, $filename = null) {
$filename = $filename ? $filename : $this->getName();
public function save(string $path, $filename = null): bool {
$filename = $filename ?: $this->getName();

return file_put_contents($path.$filename, $this->getContent()) !== false;
}
Expand Down Expand Up @@ -280,26 +280,28 @@ public function getMimeType(){
public function getExtension(){
$deprecated_guesser = "\Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser";
if (class_exists($deprecated_guesser) !== false){
/** @var \Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser $deprecated_guesser */
return $deprecated_guesser::getInstance()->guess($this->getMimeType());
}
$guesser = "\Symfony\Component\Mime\MimeTypes";
/** @var Symfony\Component\Mime\MimeTypes $guesser */
$extensions = $guesser::getDefault()->getExtensions($this->getMimeType());
return isset($extensions[0]) ? $extensions[0] : null;
return $extensions[0] ?? null;
}

/**
* Get all attributes
*
* @return array
*/
public function getAttributes(){
public function getAttributes(): array {
return $this->attributes;
}

/**
* @return Message
*/
public function getMessage(){
public function getMessage(): Message {
return $this->oMessage;
}

Expand All @@ -309,7 +311,7 @@ public function getMessage(){
*
* @return $this
*/
public function setMask($mask){
public function setMask($mask): Attachment {
if(class_exists($mask)){
$this->mask = $mask;
}
Expand All @@ -322,7 +324,7 @@ public function setMask($mask){
*
* @return string
*/
public function getMask(){
public function getMask(): string {
return $this->mask;
}

Expand Down
67 changes: 34 additions & 33 deletions src/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use ArrayAccess;
use Carbon\Carbon;
use ReturnTypeWillChange;

/**
* Class Attribute
Expand All @@ -34,10 +35,10 @@ class Attribute implements ArrayAccess {

/**
* Attribute constructor.
* @param string $name
* @param string $name
* @param array|mixed $value
*/
public function __construct($name, $value = null) {
public function __construct(string $name, $value = null) {
$this->setName($name);
$this->add($value);
}
Expand All @@ -57,7 +58,7 @@ public function __toString() {
*
* @return string
*/
public function toString(){
public function toString(): string {
return $this->__toString();
}

Expand All @@ -66,16 +67,16 @@ public function toString(){
*
* @return array
*/
public function toArray(){
public function toArray(): array {
return $this->values;
}

/**
* Convert first value to a date object
*
* @return Carbon|null
* @return Carbon
*/
public function toDate(){
public function toDate(): Carbon {
$date = $this->first();
if ($date instanceof Carbon) return $date;

Expand All @@ -85,47 +86,49 @@ public function toDate(){
/**
* Determine if a value exists at an offset.
*
* @param mixed $key
* @param mixed $offset
* @return bool
*/
public function offsetExists($key): bool {
return array_key_exists($key, $this->values);
public function offsetExists($offset): bool {
return array_key_exists($offset, $this->values);
}

/**
* Get a value at a given offset.
*
* @param mixed $key
* @param mixed $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($key) {
return $this->values[$key];
#[ReturnTypeWillChange]
public function offsetGet($offset) {
return $this->values[$offset];
}

/**
* Set the value at a given offset.
*
* @param mixed $key
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value): void {
if (is_null($key)) {
#[ReturnTypeWillChange]
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->values[] = $value;
} else {
$this->values[$key] = $value;
$this->values[$offset] = $value;
}
}

/**
* Unset the value at a given offset.
*
* @param string $key
* @param string $offset
* @return void
*/
public function offsetUnset($key): void {
unset($this->values[$key]);
#[ReturnTypeWillChange]
public function offsetUnset($offset) {
unset($this->values[$offset]);
}

/**
Expand All @@ -135,7 +138,7 @@ public function offsetUnset($key): void {
*
* @return Attribute
*/
public function add($value, $strict = false) {
public function add($value, bool $strict = false): Attribute {
if (is_array($value)) {
return $this->merge($value, $strict);
}elseif ($value !== null) {
Expand All @@ -152,11 +155,9 @@ public function add($value, $strict = false) {
*
* @return Attribute
*/
public function merge($values, $strict = false) {
if (is_array($values)) {
foreach ($values as $value) {
$this->attach($value, $strict);
}
public function merge(array $values, bool $strict = false): Attribute {
foreach ($values as $value) {
$this->attach($value, $strict);
}

return $this;
Expand All @@ -168,7 +169,7 @@ public function merge($values, $strict = false) {
*
* @return bool
*/
public function contains($value) {
public function contains($value): bool {
foreach ($this->values as $v) {
if ($v === $value) {
return true;
Expand All @@ -182,7 +183,7 @@ public function contains($value) {
* @param $value
* @param bool $strict
*/
public function attach($value, $strict = false) {
public function attach($value, bool $strict = false) {
if ($strict === true) {
if ($this->contains($value) === false) {
$this->values[] = $value;
Expand All @@ -198,7 +199,7 @@ public function attach($value, $strict = false) {
*
* @return Attribute
*/
public function setName($name){
public function setName($name): Attribute {
$this->name = $name;

return $this;
Expand All @@ -209,7 +210,7 @@ public function setName($name){
*
* @return string
*/
public function getName(){
public function getName(): string {
return $this->name;
}

Expand All @@ -218,7 +219,7 @@ public function getName(){
*
* @return array
*/
public function get(){
public function get(): array {
return $this->values;
}

Expand All @@ -227,7 +228,7 @@ public function get(){
*
* @return array
*/
public function all(){
public function all(): array {
return $this->get();
}

Expand Down Expand Up @@ -260,7 +261,7 @@ public function last(){
*
* @return int
*/
public function count(){
public function count(): int {
return count($this->values);
}
}
Loading

0 comments on commit 6e76b35

Please sign in to comment.