Skip to content

Commit

Permalink
Add parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Dec 17, 2018
1 parent bb9d11d commit 39cf6ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/Bencode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function encode($mixed): ?string
* @param string string to encode
* @return string encoded string
*/
private static function encodeString($string): string
private static function encodeString(string $string): string
{
return strlen($string).':'.$string;
}
Expand All @@ -43,7 +43,7 @@ private static function encodeString($string): string
* @param integer integer to encode
* @return string encoded integer
*/
private static function encodeInteger($integer): string
private static function encodeInteger(int $integer): string
{
return 'i'.$integer.'e';
}
Expand All @@ -52,7 +52,7 @@ private static function encodeInteger($integer): string
* @param array array to encode
* @return string encoded dictionary or list
*/
private static function encodeArray($array): string
private static function encodeArray(array $array): string
{
if (self::isList($array)) {
$return = 'l';
Expand Down Expand Up @@ -87,7 +87,7 @@ public static function decode(string $string)
* @return array|string|int decoded torrent data
* @throws BencodeException
*/
private static function decodeData(& $data)
private static function decodeData(string & $data)
{
switch (self::char($data)) {
case 'i':
Expand All @@ -109,7 +109,7 @@ private static function decodeData(& $data)
* @return array decoded dictionary
* @throws BencodeException
*/
private static function decodeDictionary(& $data): array
private static function decodeDictionary(string & $data): array
{
$dictionary = [];
$previous = null;
Expand Down Expand Up @@ -139,7 +139,7 @@ private static function decodeDictionary(& $data): array
* @return array decoded list
* @throws BencodeException
*/
private static function decodeList(& $data): array
private static function decodeList(string & $data): array
{
$list = [];
while (($char = self::char($data)) !== 'e') {
Expand All @@ -157,7 +157,7 @@ private static function decodeList(& $data): array
* @return string decoded string
* @throws BencodeException
*/
private static function decodeString(& $data): string
private static function decodeString(string & $data): string
{
if (self::char($data) === '0' && $data[1] ?? null !== ':') {
throw new BencodeException(BencodeException::STRING_LEADING_ZERO);
Expand All @@ -179,7 +179,7 @@ private static function decodeString(& $data): string
* @return integer decoded integer
* @throws BencodeException
*/
private static function decodeInteger(& $data): int
private static function decodeInteger(string & $data): int
{
$start = 0;
$end = strpos($data, 'e');
Expand All @@ -204,7 +204,7 @@ private static function decodeInteger(& $data): int
* @param array $array
* @return bool
*/
protected static function isList($array): bool
protected static function isList(array $array): bool
{
foreach (array_keys($array) as $key) {
if (!is_int($key)) {
Expand All @@ -218,7 +218,7 @@ protected static function isList($array): bool
* @param string $data
* @return bool|string
*/
private static function char($data)
private static function char(string $data)
{
return empty($data) ?
false :
Expand Down
4 changes: 2 additions & 2 deletions src/FileHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FileHasher
* @param int $pieceLength
* @throws \Exception
*/
public function __construct($path, $pieceLength)
public function __construct(string $path, int $pieceLength)
{
$this->path = $path;
$this->length = 0;
Expand Down Expand Up @@ -128,7 +128,7 @@ public function __construct($path, $pieceLength)
* @param array $hashes
* @return mixed
*/
public static function rootHash($hashes)
public static function rootHash(array $hashes)
{
assert(count($hashes) & (count($hashes) - 1) === 0);
while (count($hashes) > 1) {
Expand Down
10 changes: 5 additions & 5 deletions src/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Torrent
* @param int $pieceLength
* @throws \Exception
*/
public function __construct($pieceLength)
public function __construct(int $pieceLength)
{
assert($pieceLength >= self::BLOCK_SIZE, new \Exception);
assert($pieceLength, new \Exception);
Expand All @@ -79,7 +79,7 @@ public function __construct($pieceLength)
* @param string $path
* @throws \Exception
*/
public function prepare($path): void
public function prepare(string $path): void
{
$this->basePath = realpath($path);
$this->name = basename($path);
Expand Down Expand Up @@ -149,7 +149,7 @@ public function infoHashV1(): string
* @return array
* @throws \Exception
*/
private function walkPath($path): array
private function walkPath(string $path): array
{
if (file_exists($path)) {
try {
Expand Down Expand Up @@ -220,7 +220,7 @@ private function walkPath($path): array
* @param bool $hybrid
* @return array
*/
public function create($tracker, $hybrid = true): array
public function create(string $tracker, bool $hybrid = true): array
{
$info = [
'name' => $this->name,
Expand Down Expand Up @@ -262,7 +262,7 @@ public function create($tracker, $hybrid = true): array
* @return bool|int
* @throws \Exception
*/
public function save($filename = null)
public function save(?string $filename = null)
{
return file_put_contents(
$filename ?? $this->info['name'].'.torrent',
Expand Down

0 comments on commit 39cf6ab

Please sign in to comment.