Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(php): add PHPStan for static code analysis #3655

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
374 changes: 220 additions & 154 deletions clients/algoliasearch-client-php/composer.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions clients/algoliasearch-client-php/lib/ApiException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

namespace Algolia\AlgoliaSearch;

/**
Expand Down
16 changes: 8 additions & 8 deletions clients/algoliasearch-client-php/lib/Cache/NullCacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@

final class NullCacheDriver implements CacheInterface
{
public function get($key, $default = null)
public function get($key, $default = null): mixed
{
return $default;
}

public function set($key, $value, $ttl = null)
public function set($key, $value, $ttl = null): bool
{
return true;
}

public function delete($key)
public function delete($key): bool
{
return true;
}

public function clear()
public function clear(): bool
{
return true;
}

public function getMultiple($keys, $default = null)
public function getMultiple($keys, $default = null): iterable
{
$return = [];

Expand All @@ -37,17 +37,17 @@ public function getMultiple($keys, $default = null)
return $return;
}

public function setMultiple($values, $ttl = null)
public function setMultiple($values, $ttl = null): bool
{
return true;
}

public function deleteMultiple($keys)
public function deleteMultiple($keys): bool
{
return true;
}

public function has($key)
public function has($key): bool
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

namespace Algolia\AlgoliaSearch\Configuration;

abstract class ConfigWithRegion extends Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

namespace Algolia\AlgoliaSearch\Configuration;

use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
Expand Down
28 changes: 14 additions & 14 deletions clients/algoliasearch-client-php/lib/Http/Psr7/BufferStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,65 +32,65 @@ public function __construct($hwm = 16384)
$this->hwm = $hwm;
}

public function __toString()
public function __toString(): string
{
return $this->getContents();
}

public function getContents()
public function getContents(): string
{
$buffer = $this->buffer;
$this->buffer = '';

return $buffer;
}

public function close()
public function close(): void
{
$this->buffer = '';
}

public function detach()
public function detach(): void
{
$this->close();
}

public function getSize()
public function getSize(): int
{
return mb_strlen($this->buffer);
}

public function isReadable()
public function isReadable(): bool
{
return true;
}

public function isWritable()
public function isWritable(): bool
{
return true;
}

public function isSeekable()
public function isSeekable(): bool
{
return false;
}

public function rewind()
public function rewind(): void
{
$this->seek(0);
}

public function seek($offset, $whence = SEEK_SET)
public function seek($offset, $whence = SEEK_SET): void
{
throw new \RuntimeException('Cannot seek a BufferStream');
}

public function eof()
public function eof(): bool
{
return 0 === mb_strlen($this->buffer);
}

public function tell()
public function tell(): int
{
throw new \RuntimeException('Cannot determine the position of a BufferStream');
}
Expand All @@ -100,7 +100,7 @@ public function tell()
*
* @param mixed $length
*/
public function read($length)
public function read($length): string
{
$currentLength = mb_strlen($this->buffer);

Expand All @@ -122,7 +122,7 @@ public function read($length)
*
* @param mixed $string
*/
public function write($string)
public function write($string): int
{
$this->buffer .= $string;

Expand Down
28 changes: 14 additions & 14 deletions clients/algoliasearch-client-php/lib/Http/Psr7/PumpStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(callable $source, array $options = [])
$this->buffer = new BufferStream();
}

public function __toString()
public function __toString(): string
{
try {
return copy_to_string($this);
Expand All @@ -62,63 +62,63 @@ public function __toString()
}
}

public function close()
public function close(): void
{
$this->detach();
}

public function detach()
public function detach(): void
{
$this->tellPos = false;
$this->source = null;
}

public function getSize()
public function getSize(): ?int
{
return $this->size;
}

public function tell()
public function tell(): int
{
return $this->tellPos;
}

public function eof()
public function eof(): bool
{
return !$this->source;
}

public function isSeekable()
public function isSeekable(): bool
{
return false;
}

public function rewind()
public function rewind(): void
{
$this->seek(0);
}

public function seek($offset, $whence = SEEK_SET)
public function seek($offset, $whence = SEEK_SET): void
{
throw new \RuntimeException('Cannot seek a PumpStream');
}

public function isWritable()
public function isWritable(): bool
{
return false;
}

public function write($string)
public function write($string): int
{
throw new \RuntimeException('Cannot write to a PumpStream');
}

public function isReadable()
public function isReadable(): bool
{
return true;
}

public function read($length)
public function read($length): string
{
$data = $this->buffer->read($length);
$readLen = mb_strlen($data);
Expand All @@ -134,7 +134,7 @@ public function read($length)
return $data;
}

public function getContents()
public function getContents(): string
{
$result = '';
while (!$this->eof()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
<?php

// {{{generationBanner}}}

namespace {{modelPackage}};
namespace Algolia\AlgoliaSearch\Model;

/**
* Interface abstracting model access.
*
* @package {{modelPackage}}
*/
interface ModelInterface
{
/**
* Array of property to type mappings. Used for (de)serialization
* Array of property to type mappings. Used for (de)serialization.
*
* @return array
*/
public static function modelTypes();

/**
* Array of property to format mappings. Used for (de)serialization
* Array of property to format mappings. Used for (de)serialization.
*
* @return array
*/
public static function modelFormats();

/**
* Array of attributes to setter functions (for deserialization of responses)
* Array of attributes to setter functions (for deserialization of responses).
*
* @return array
*/
public static function setters();

/**
* Array of attributes to getter functions (for serialization of requests)
* Array of attributes to getter functions (for serialization of requests).
*
* @return array
*/
Expand All @@ -48,7 +44,7 @@ public function listInvalidProperties();

/**
* Validate all the properties in the model
* return true if all passed
* return true if all passed.
*
* @return bool
*/
Expand Down
39 changes: 2 additions & 37 deletions clients/algoliasearch-client-php/lib/ObjectSerializer.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

namespace Algolia\AlgoliaSearch;

use Algolia\AlgoliaSearch\Model\ModelInterface;

/**
* ObjectSerializer Class Doc Comment.
*
Expand Down Expand Up @@ -86,23 +86,6 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
return (string) $data;
}

/**
* Sanitize filename by removing path.
* e.g. ../../sun.gif becomes sun.gif.
*
* @param string $filename filename to be sanitized
*
* @return string the sanitized filename
*/
public static function sanitizeFilename($filename)
{
if (preg_match('/.*[\\/\\\\](.*)$/', $filename, $match)) {
return $match[1];
}

return $filename;
}

/**
* Take value and turn it into a string suitable for inclusion in
* the path, by url-encoding.
Expand Down Expand Up @@ -154,24 +137,6 @@ public static function toHeaderValue($value)
return self::toString($value);
}

/**
* Take value and turn it into a string suitable for inclusion in
* the http body (form parameter). If it's a string, pass through unchanged
* If it's a datetime object, format it in ISO8601.
*
* @param \SplFileObject|string $value the value of the form parameter
*
* @return string the form string
*/
public static function toFormValue($value)
{
if ($value instanceof \SplFileObject) {
return $value->getRealPath();
}

return self::toString($value);
}

/**
* Take value and turn it into a string suitable for inclusion in
* the parameter. If it's a string, pass through unchanged
Expand Down
4 changes: 4 additions & 0 deletions clients/algoliasearch-client-php/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
excludePaths:
- vendor/*
level: max
Loading
Loading