Skip to content

Commit

Permalink
Merge pull request JetBrains#912 from JetBrains/php8_magic_methods_si…
Browse files Browse the repository at this point in the history
…gnatures

WI-54641 Add type declarations to magic method signatures
  • Loading branch information
pestretsov authored Oct 1, 2020
2 parents 874def3 + fbd76af commit 74241c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 14 additions & 15 deletions standard/_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function __destruct() {}
* @return mixed
* @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods
*/
public function __call($name, $arguments) {}
public function __call(string $name, array $arguments) {}

/**
* is triggered when invoking inaccessible methods in a static context.
Expand All @@ -269,7 +269,7 @@ public function __call($name, $arguments) {}
* @return mixed
* @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods
*/
public static function __callStatic($name, $arguments) {}
public static function __callStatic(string $name, array $arguments) {}

/**
* is utilized for reading data from inaccessible members.
Expand All @@ -278,7 +278,7 @@ public static function __callStatic($name, $arguments) {}
* @return mixed
* @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members
*/
public function __get($name) {}
public function __get(string $name) {}

/**
* run when writing data to inaccessible members.
Expand All @@ -288,7 +288,7 @@ public function __get($name) {}
* @return void
* @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members
*/
public function __set($name, $value) {}
public function __set(string $name, $value): void {}

/**
* is triggered by calling isset() or empty() on inaccessible members.
Expand All @@ -297,15 +297,15 @@ public function __set($name, $value) {}
* @return bool
* @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members
*/
public function __isset($name) {}
public function __isset(string $name): bool {}
/**
* is invoked when unset() is used on inaccessible members.
*
* @param string $name
* @return void
* @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members
*/
public function __unset($name) {}
public function __unset(string $name): void {}

/**
* serialize() checks if your class has a function with the magic name __sleep.
Expand All @@ -318,7 +318,7 @@ public function __unset($name) {}
* @return string[]
* @link https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep
*/
public function __sleep() {}
public function __sleep(): array {}

/**
* unserialize() checks for the presence of a function with the magic name __wakeup.
Expand All @@ -329,15 +329,15 @@ public function __sleep() {}
* @return void
* @link https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep
*/
public function __wakeup() {}
public function __wakeup(): void {}

/**
* The __toString method allows a class to decide how it will react when it is converted to a string.
*
* @return string
* @link https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
*/
public function __toString() {}
public function __toString(): string {}

/**
* The __invoke method is called when a script tries to call an object as a function.
Expand All @@ -350,22 +350,21 @@ public function __invoke() {}
/**
* This method is called by var_dump() when dumping an object to get the properties that should be shown.
* If the method isn't defined on an object, then all public, protected and private properties will be shown.
* @since 5.6
*
* @return array
* @return array|null
* @link https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
*/
public function __debugInfo(){}
public function __debugInfo(): ?array {}

/**
* This static method is called for classes exported by var_export() since PHP 5.1.0.
* The only parameter of this method is an array containing exported properties in the form array('property' => value, ...).
*
* @param array $an_array
* @return mixed
* @return object
* @link https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.set-state
*/
public static function __set_state($an_array) {}
public static function __set_state(array $an_array): object {}

/**
* When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties.
Expand All @@ -377,7 +376,7 @@ public static function __set_state($an_array) {}
* @return void
* @link https://php.net/manual/en/language.oop5.cloning.php
*/
public function __clone() {}
public function __clone(): void {}

/**
* Returns array containing all the necessary state of the object.
Expand Down
2 changes: 2 additions & 0 deletions tests/StubsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ public function testCoreMethodsTypeHints(string $methodName, PHPMethod $stubFunc
$firstSinceVersion = array_pop($sinceVersions);
} elseif ($stubFunction->hasInheritDocTag) {
self::markTestSkipped("Function '$methodName' contains inheritdoc.");
} elseif ($stubFunction->parentName === "___PHPSTORM_HELPERS\object") {
self::markTestSkipped("Function '$methodName' is declared in ___PHPSTORM_HELPERS\object.");
} elseif ($stubFunction->name === "__construct"){
$parentClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($stubFunction->parentName);
if (!empty($parentClass->sinceTags)) {
Expand Down

0 comments on commit 74241c7

Please sign in to comment.