Skip to content

Commit 84053c4

Browse files
feat!: remove confusing toArray() alias to __serialize() in favour of toProperties()
1 parent 0112a9a commit 84053c4

File tree

9 files changed

+10
-63
lines changed

9 files changed

+10
-63
lines changed

src/CasGenerator/CasGeneratorGenerateCasParams.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@
1111
use CasParser\Core\Contracts\BaseModel;
1212

1313
/**
14-
* An object containing the method's parameters.
15-
* Example usage:
16-
* ```
17-
* $params = (new CasGeneratorGenerateCasParams); // set properties as needed
18-
* $client->casGenerator->generateCas(...$params->toArray());
19-
* ```
2014
* This endpoint generates CAS (Consolidated Account Statement) documents by submitting a mailback request to the specified CAS authority.
2115
* Currently only supports KFintech, with plans to support CAMS, CDSL, and NSDL in the future.
2216
*
23-
* @method toArray()
24-
* Returns the parameters as an associative array suitable for passing to the client method.
25-
*
26-
* `$client->casGenerator->generateCas(...$params->toArray());`
27-
*
2817
* @see CasParser\CasGenerator->generateCas
2918
*
3019
* @phpstan-type cas_generator_generate_cas_params = array{

src/CasParser/CasParserCamsKfintechParams.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,9 @@
1010
use CasParser\Core\Contracts\BaseModel;
1111

1212
/**
13-
* An object containing the method's parameters.
14-
* Example usage:
15-
* ```
16-
* $params = (new CasParserCamsKfintechParams); // set properties as needed
17-
* $client->casParser->camsKfintech(...$params->toArray());
18-
* ```
1913
* This endpoint specifically parses CAMS/KFintech CAS (Consolidated Account Statement) PDF files and returns data in a unified format.
2014
* Use this endpoint when you know the PDF is from CAMS or KFintech.
2115
*
22-
* @method toArray()
23-
* Returns the parameters as an associative array suitable for passing to the client method.
24-
*
25-
* `$client->casParser->camsKfintech(...$params->toArray());`
26-
*
2716
* @see CasParser\CasParser->camsKfintech
2817
*
2918
* @phpstan-type cas_parser_cams_kfintech_params = array{

src/CasParser/CasParserCdslParams.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,9 @@
1010
use CasParser\Core\Contracts\BaseModel;
1111

1212
/**
13-
* An object containing the method's parameters.
14-
* Example usage:
15-
* ```
16-
* $params = (new CasParserCdslParams); // set properties as needed
17-
* $client->casParser->cdsl(...$params->toArray());
18-
* ```
1913
* This endpoint specifically parses CDSL CAS (Consolidated Account Statement) PDF files and returns data in a unified format.
2014
* Use this endpoint when you know the PDF is from CDSL.
2115
*
22-
* @method toArray()
23-
* Returns the parameters as an associative array suitable for passing to the client method.
24-
*
25-
* `$client->casParser->cdsl(...$params->toArray());`
26-
*
2716
* @see CasParser\CasParser->cdsl
2817
*
2918
* @phpstan-type cas_parser_cdsl_params = array{

src/CasParser/CasParserNsdlParams.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,9 @@
1010
use CasParser\Core\Contracts\BaseModel;
1111

1212
/**
13-
* An object containing the method's parameters.
14-
* Example usage:
15-
* ```
16-
* $params = (new CasParserNsdlParams); // set properties as needed
17-
* $client->casParser->nsdl(...$params->toArray());
18-
* ```
1913
* This endpoint specifically parses NSDL CAS (Consolidated Account Statement) PDF files and returns data in a unified format.
2014
* Use this endpoint when you know the PDF is from NSDL.
2115
*
22-
* @method toArray()
23-
* Returns the parameters as an associative array suitable for passing to the client method.
24-
*
25-
* `$client->casParser->nsdl(...$params->toArray());`
26-
*
2716
* @see CasParser\CasParser->nsdl
2817
*
2918
* @phpstan-type cas_parser_nsdl_params = array{

src/CasParser/CasParserSmartParseParams.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,9 @@
1010
use CasParser\Core\Contracts\BaseModel;
1111

1212
/**
13-
* An object containing the method's parameters.
14-
* Example usage:
15-
* ```
16-
* $params = (new CasParserSmartParseParams); // set properties as needed
17-
* $client->casParser->smartParse(...$params->toArray());
18-
* ```
1913
* This endpoint parses CAS (Consolidated Account Statement) PDF files from NSDL, CDSL, or CAMS/KFintech and returns data in a unified format.
2014
* It auto-detects the CAS type and transforms the data into a consistent structure regardless of the source.
2115
*
22-
* @method toArray()
23-
* Returns the parameters as an associative array suitable for passing to the client method.
24-
*
25-
* `$client->casParser->smartParse(...$params->toArray());`
26-
*
2716
* @see CasParser\CasParser->smartParse
2817
*
2918
* @phpstan-type cas_parser_smart_parse_params = array{

src/Core/Concerns/SdkModel.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ trait SdkModel
3232
*/
3333
public function __serialize(): array
3434
{
35-
$rows = [...Util::get_object_vars($this), ...$this->_data]; // @phpstan-ignore-line
35+
$properties = $this->toProperties(); // @phpstan-ignore-line
3636

37-
return array_map(static fn ($v) => self::serialize($v), array: $rows);
37+
return array_map(static fn ($v) => self::serialize($v), array: $properties);
3838
}
3939

4040
/**
@@ -98,11 +98,13 @@ public function __get(string $key): mixed
9898
}
9999

100100
/**
101+
* @internal
102+
*
101103
* @return Shape
102104
*/
103-
public function toArray(): array
105+
public function toProperties(): array
104106
{
105-
return $this->__serialize(); // @phpstan-ignore-line
107+
return [...Util::get_object_vars($this), ...$this->_data]; // @phpstan-ignore-line
106108
}
107109

108110
/**
@@ -257,7 +259,7 @@ private function initialize(): void
257259
private static function serialize(mixed $value): mixed
258260
{
259261
if ($value instanceof BaseModel) {
260-
return $value->toArray();
262+
return $value->toProperties();
261263
}
262264

263265
if (is_array($value)) {

src/Core/Contracts/BaseModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
interface BaseModel extends \ArrayAccess, \JsonSerializable, \Stringable, ConverterSource
1515
{
1616
/** @return array<string, mixed> */
17-
public function toArray(): array;
17+
public function toProperties(): array;
1818
}

src/Core/Conversion/ModelOf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function from(array $data): BaseModel
105105
public function dump(mixed $value, DumpState $state): mixed
106106
{
107107
if ($value instanceof BaseModel) {
108-
$value = $value->toArray();
108+
$value = $value->toProperties();
109109
}
110110

111111
if (is_array($value)) {

src/RequestOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct()
8181
*/
8282
public static function parse(RequestOptions|array|null ...$options): self
8383
{
84-
$parsed = array_map(static fn ($o) => $o instanceof self ? $o->toArray() : $o ?? [], array: $options);
84+
$parsed = array_map(static fn ($o) => $o instanceof self ? $o->toProperties() : $o ?? [], array: $options);
8585

8686
return self::with(...array_merge(...$parsed)); // @phpstan-ignore-line
8787
}

0 commit comments

Comments
 (0)