diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index 8dec9f0..f7222cd 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -17,3 +17,6 @@ jobs: - name: Check release environment run: | bash ./bin/check-release-environment + env: + PACKAGIST_USERNAME: ${{ secrets.CAS_PARSER_PACKAGIST_USERNAME || secrets.PACKAGIST_USERNAME }} + PACKAGIST_SAFE_KEY: ${{ secrets.CAS_PARSER_PACKAGIST_SAFE_KEY || secrets.PACKAGIST_SAFE_KEY }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 10f3091..6b7b74c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0" + ".": "0.3.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 92721c7..06e7614 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 5 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-b7fdba3d3f97c7debc22c7ca30b828bce81bcd64648df8c94029b27a3321ebb9.yml -openapi_spec_hash: 03f1315f1d32ada42445ca920f047dff +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-9eaed98ce5934f11e901cef376a28257d2c196bd3dba7c690babc6741a730ded.yml +openapi_spec_hash: b76e4e830c4d03ba4cf9429bb9fb9c8a config_hash: cb5d75abef6264b5d86448caf7295afa diff --git a/CHANGELOG.md b/CHANGELOG.md index 57b6fa7..399b322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ # Changelog +## 0.3.0 (2025-11-05) + +Full Changelog: [v0.2.0...v0.3.0](https://github.com/CASParser/cas-parser-php/compare/v0.2.0...v0.3.0) + +### ⚠ BREAKING CHANGES + +* remove confusing `toArray()` alias to `__serialize()` in favour of `toProperties()` + +### Features + +* **api:** api update ([da8b838](https://github.com/CASParser/cas-parser-php/commit/da8b83821dab28680f72e98a943af25df296e314)) +* remove confusing `toArray()` alias to `__serialize()` in favour of `toProperties()` ([84053c4](https://github.com/CASParser/cas-parser-php/commit/84053c4b32db33f341e5e9bf89f2aabe982a2695)) + + +### Bug Fixes + +* **ci:** release doctor workflow ([d7d0f00](https://github.com/CASParser/cas-parser-php/commit/d7d0f005e9022cce83d3316626e5746a3a02b694)) +* ensure auth methods return non-nullable arrays ([fd0ab3b](https://github.com/CASParser/cas-parser-php/commit/fd0ab3bb4232369f31350fb47d0aca4d916f5739)) +* inverted retry condition ([0112a9a](https://github.com/CASParser/cas-parser-php/commit/0112a9a50be77cb4681413034b3d88d791774f6c)) + + +### Chores + +* add license ([7742369](https://github.com/CASParser/cas-parser-php/commit/7742369f0a91046a7aa843391627e8931c6280f8)) +* **client:** send metadata headers ([9a72241](https://github.com/CASParser/cas-parser-php/commit/9a72241ae57939ae08709709a26a87f1ad83d9e2)) +* **docs:** update readme formatting ([f992e92](https://github.com/CASParser/cas-parser-php/commit/f992e921cd7043ea562ad58fb01905bd2039fa50)) +* refactor methods ([e25fa02](https://github.com/CASParser/cas-parser-php/commit/e25fa02ca0d7d49d88f1859c99e2db925a74e722)) +* use pascal case for phpstan typedefs ([574d168](https://github.com/CASParser/cas-parser-php/commit/574d1680fbbaccfc4281a98e33d205f4d8a7e043)) + ## 0.2.0 (2025-09-13) Full Changelog: [v0.1.0...v0.2.0](https://github.com/CASParser/cas-parser-php/compare/v0.1.0...v0.2.0) diff --git a/README.md b/README.md index 75f8882..c30e278 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,6 @@ use CasParser\RequestOptions; $client = new Client(maxRetries: 0); // Or, configure per-request: - $result = $client->casParser->smartParse( requestOptions: RequestOptions::with(maxRetries: 5) ); diff --git a/composer.json b/composer.json index 7163498..1a19d72 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,11 @@ { "$schema": "https://getcomposer.org/schema.json", + "license": "Apache-2.0", "autoload": { - "files": ["src/Core.php", "src/Client.php"], + "files": [ + "src/Core.php", + "src/Client.php" + ], "psr-4": { "CasParser\\": "src/" } diff --git a/release-please-config.json b/release-please-config.json index 1891660..5c15181 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -61,6 +61,7 @@ ], "release-type": "php", "extra-files": [ - "README.md" + "README.md", + "src/Client.php" ] } \ No newline at end of file diff --git a/scripts/lint b/scripts/lint index 6d629c2..13f2f01 100755 --- a/scripts/lint +++ b/scripts/lint @@ -5,4 +5,4 @@ set -e cd -- "$(dirname -- "$0")/.." echo "==> Running PHPStan" -exec -- ./vendor/bin/phpstan analyse --memory-limit=1G +exec -- ./vendor/bin/phpstan analyse --memory-limit=2G diff --git a/src/CasGenerator/CasGeneratorGenerateCasParams.php b/src/CasGenerator/CasGeneratorGenerateCasParams.php index 3f3de18..02614fa 100644 --- a/src/CasGenerator/CasGeneratorGenerateCasParams.php +++ b/src/CasGenerator/CasGeneratorGenerateCasParams.php @@ -11,23 +11,12 @@ use CasParser\Core\Contracts\BaseModel; /** - * An object containing the method's parameters. - * Example usage: - * ``` - * $params = (new CasGeneratorGenerateCasParams); // set properties as needed - * $client->casGenerator->generateCas(...$params->toArray()); - * ``` * This endpoint generates CAS (Consolidated Account Statement) documents by submitting a mailback request to the specified CAS authority. * Currently only supports KFintech, with plans to support CAMS, CDSL, and NSDL in the future. * - * @method toArray() - * Returns the parameters as an associative array suitable for passing to the client method. - * - * `$client->casGenerator->generateCas(...$params->toArray());` - * * @see CasParser\CasGenerator->generateCas * - * @phpstan-type cas_generator_generate_cas_params = array{ + * @phpstan-type CasGeneratorGenerateCasParamsShape = array{ * email: string, * fromDate: string, * password: string, @@ -38,7 +27,7 @@ */ final class CasGeneratorGenerateCasParams implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; use SdkParams; @@ -127,7 +116,7 @@ public static function with( $obj->password = $password; $obj->toDate = $toDate; - null !== $casAuthority && $obj->casAuthority = $casAuthority instanceof CasAuthority ? $casAuthority->value : $casAuthority; + null !== $casAuthority && $obj['casAuthority'] = $casAuthority; null !== $panNo && $obj->panNo = $panNo; return $obj; @@ -185,7 +174,7 @@ public function withToDate(string $toDate): self public function withCasAuthority(CasAuthority|string $casAuthority): self { $obj = clone $this; - $obj->casAuthority = $casAuthority instanceof CasAuthority ? $casAuthority->value : $casAuthority; + $obj['casAuthority'] = $casAuthority; return $obj; } diff --git a/src/CasGenerator/CasGeneratorGenerateCasResponse.php b/src/CasGenerator/CasGeneratorGenerateCasResponse.php index 86298f8..736691f 100644 --- a/src/CasGenerator/CasGeneratorGenerateCasResponse.php +++ b/src/CasGenerator/CasGeneratorGenerateCasResponse.php @@ -6,22 +6,22 @@ use CasParser\Core\Attributes\Api; use CasParser\Core\Concerns\SdkModel; +use CasParser\Core\Concerns\SdkResponse; use CasParser\Core\Contracts\BaseModel; +use CasParser\Core\Conversion\Contracts\ResponseConverter; /** - * @phpstan-type cas_generator_generate_cas_response = array{ + * @phpstan-type CasGeneratorGenerateCasResponseShape = array{ * msg?: string, status?: string * } - * When used in a response, this type parameter can define a $rawResponse property. - * @template TRawResponse of object = object{} - * - * @mixin TRawResponse */ -final class CasGeneratorGenerateCasResponse implements BaseModel +final class CasGeneratorGenerateCasResponse implements BaseModel, ResponseConverter { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; + use SdkResponse; + #[Api(optional: true)] public ?string $msg; diff --git a/src/CasParser/CasParserCamsKfintechParams.php b/src/CasParser/CasParserCamsKfintechParams.php index 8e09e3b..197b273 100644 --- a/src/CasParser/CasParserCamsKfintechParams.php +++ b/src/CasParser/CasParserCamsKfintechParams.php @@ -10,29 +10,18 @@ use CasParser\Core\Contracts\BaseModel; /** - * An object containing the method's parameters. - * Example usage: - * ``` - * $params = (new CasParserCamsKfintechParams); // set properties as needed - * $client->casParser->camsKfintech(...$params->toArray()); - * ``` * This endpoint specifically parses CAMS/KFintech CAS (Consolidated Account Statement) PDF files and returns data in a unified format. * Use this endpoint when you know the PDF is from CAMS or KFintech. * - * @method toArray() - * Returns the parameters as an associative array suitable for passing to the client method. - * - * `$client->casParser->camsKfintech(...$params->toArray());` - * * @see CasParser\CasParser->camsKfintech * - * @phpstan-type cas_parser_cams_kfintech_params = array{ + * @phpstan-type CasParserCamsKfintechParamsShape = array{ * password?: string, pdfFile?: string, pdfURL?: string * } */ final class CasParserCamsKfintechParams implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; use SdkParams; diff --git a/src/CasParser/CasParserCdslParams.php b/src/CasParser/CasParserCdslParams.php index d48b9b2..e3e93f4 100644 --- a/src/CasParser/CasParserCdslParams.php +++ b/src/CasParser/CasParserCdslParams.php @@ -10,29 +10,18 @@ use CasParser\Core\Contracts\BaseModel; /** - * An object containing the method's parameters. - * Example usage: - * ``` - * $params = (new CasParserCdslParams); // set properties as needed - * $client->casParser->cdsl(...$params->toArray()); - * ``` * This endpoint specifically parses CDSL CAS (Consolidated Account Statement) PDF files and returns data in a unified format. * Use this endpoint when you know the PDF is from CDSL. * - * @method toArray() - * Returns the parameters as an associative array suitable for passing to the client method. - * - * `$client->casParser->cdsl(...$params->toArray());` - * * @see CasParser\CasParser->cdsl * - * @phpstan-type cas_parser_cdsl_params = array{ + * @phpstan-type CasParserCdslParamsShape = array{ * password?: string, pdfFile?: string, pdfURL?: string * } */ final class CasParserCdslParams implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; use SdkParams; diff --git a/src/CasParser/CasParserNsdlParams.php b/src/CasParser/CasParserNsdlParams.php index 98320b2..20911bf 100644 --- a/src/CasParser/CasParserNsdlParams.php +++ b/src/CasParser/CasParserNsdlParams.php @@ -10,29 +10,18 @@ use CasParser\Core\Contracts\BaseModel; /** - * An object containing the method's parameters. - * Example usage: - * ``` - * $params = (new CasParserNsdlParams); // set properties as needed - * $client->casParser->nsdl(...$params->toArray()); - * ``` * This endpoint specifically parses NSDL CAS (Consolidated Account Statement) PDF files and returns data in a unified format. * Use this endpoint when you know the PDF is from NSDL. * - * @method toArray() - * Returns the parameters as an associative array suitable for passing to the client method. - * - * `$client->casParser->nsdl(...$params->toArray());` - * * @see CasParser\CasParser->nsdl * - * @phpstan-type cas_parser_nsdl_params = array{ + * @phpstan-type CasParserNsdlParamsShape = array{ * password?: string, pdfFile?: string, pdfURL?: string * } */ final class CasParserNsdlParams implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; use SdkParams; diff --git a/src/CasParser/CasParserSmartParseParams.php b/src/CasParser/CasParserSmartParseParams.php index 525ebf1..4de5e15 100644 --- a/src/CasParser/CasParserSmartParseParams.php +++ b/src/CasParser/CasParserSmartParseParams.php @@ -10,29 +10,18 @@ use CasParser\Core\Contracts\BaseModel; /** - * An object containing the method's parameters. - * Example usage: - * ``` - * $params = (new CasParserSmartParseParams); // set properties as needed - * $client->casParser->smartParse(...$params->toArray()); - * ``` * This endpoint parses CAS (Consolidated Account Statement) PDF files from NSDL, CDSL, or CAMS/KFintech and returns data in a unified format. * It auto-detects the CAS type and transforms the data into a consistent structure regardless of the source. * - * @method toArray() - * Returns the parameters as an associative array suitable for passing to the client method. - * - * `$client->casParser->smartParse(...$params->toArray());` - * * @see CasParser\CasParser->smartParse * - * @phpstan-type cas_parser_smart_parse_params = array{ + * @phpstan-type CasParserSmartParseParamsShape = array{ * password?: string, pdfFile?: string, pdfURL?: string * } */ final class CasParserSmartParseParams implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; use SdkParams; diff --git a/src/CasParser/UnifiedResponse.php b/src/CasParser/UnifiedResponse.php index 0eda57c..a164884 100644 --- a/src/CasParser/UnifiedResponse.php +++ b/src/CasParser/UnifiedResponse.php @@ -9,30 +9,32 @@ use CasParser\CasParser\UnifiedResponse\Investor; use CasParser\CasParser\UnifiedResponse\Meta; use CasParser\CasParser\UnifiedResponse\MutualFund; +use CasParser\CasParser\UnifiedResponse\Np; use CasParser\CasParser\UnifiedResponse\Summary; use CasParser\Core\Attributes\Api; use CasParser\Core\Concerns\SdkModel; +use CasParser\Core\Concerns\SdkResponse; use CasParser\Core\Contracts\BaseModel; +use CasParser\Core\Conversion\Contracts\ResponseConverter; /** - * @phpstan-type unified_response = array{ + * @phpstan-type UnifiedResponseShape = array{ * dematAccounts?: list, * insurance?: Insurance, * investor?: Investor, * meta?: Meta, * mutualFunds?: list, + * nps?: list, * summary?: Summary, * } - * When used in a response, this type parameter can define a $rawResponse property. - * @template TRawResponse of object = object{} - * - * @mixin TRawResponse */ -final class UnifiedResponse implements BaseModel +final class UnifiedResponse implements BaseModel, ResponseConverter { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; + use SdkResponse; + /** @var list|null $dematAccounts */ #[Api('demat_accounts', list: DematAccount::class, optional: true)] public ?array $dematAccounts; @@ -50,6 +52,14 @@ final class UnifiedResponse implements BaseModel #[Api('mutual_funds', list: MutualFund::class, optional: true)] public ?array $mutualFunds; + /** + * List of NPS accounts. + * + * @var list|null $nps + */ + #[Api(list: Np::class, optional: true)] + public ?array $nps; + #[Api(optional: true)] public ?Summary $summary; @@ -65,6 +75,7 @@ public function __construct() * * @param list $dematAccounts * @param list $mutualFunds + * @param list $nps */ public static function with( ?array $dematAccounts = null, @@ -72,6 +83,7 @@ public static function with( ?Investor $investor = null, ?Meta $meta = null, ?array $mutualFunds = null, + ?array $nps = null, ?Summary $summary = null, ): self { $obj = new self; @@ -81,6 +93,7 @@ public static function with( null !== $investor && $obj->investor = $investor; null !== $meta && $obj->meta = $meta; null !== $mutualFunds && $obj->mutualFunds = $mutualFunds; + null !== $nps && $obj->nps = $nps; null !== $summary && $obj->summary = $summary; return $obj; @@ -132,6 +145,19 @@ public function withMutualFunds(array $mutualFunds): self return $obj; } + /** + * List of NPS accounts. + * + * @param list $nps + */ + public function withNps(array $nps): self + { + $obj = clone $this; + $obj->nps = $nps; + + return $obj; + } + public function withSummary(Summary $summary): self { $obj = clone $this; diff --git a/src/CasParser/UnifiedResponse/DematAccount.php b/src/CasParser/UnifiedResponse/DematAccount.php index 0c57e41..c3df839 100644 --- a/src/CasParser/UnifiedResponse/DematAccount.php +++ b/src/CasParser/UnifiedResponse/DematAccount.php @@ -7,12 +7,13 @@ use CasParser\CasParser\UnifiedResponse\DematAccount\AdditionalInfo; use CasParser\CasParser\UnifiedResponse\DematAccount\DematType; use CasParser\CasParser\UnifiedResponse\DematAccount\Holdings; +use CasParser\CasParser\UnifiedResponse\DematAccount\LinkedHolder; use CasParser\Core\Attributes\Api; use CasParser\Core\Concerns\SdkModel; use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type demat_account = array{ + * @phpstan-type DematAccountShape = array{ * additionalInfo?: AdditionalInfo, * boID?: string, * clientID?: string, @@ -20,12 +21,13 @@ * dpID?: string, * dpName?: string, * holdings?: Holdings, + * linkedHolders?: list, * value?: float, * } */ final class DematAccount implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @@ -69,6 +71,14 @@ final class DematAccount implements BaseModel #[Api(optional: true)] public ?Holdings $holdings; + /** + * List of account holders linked to this demat account. + * + * @var list|null $linkedHolders + */ + #[Api('linked_holders', list: LinkedHolder::class, optional: true)] + public ?array $linkedHolders; + /** * Total value of the demat account. */ @@ -86,6 +96,7 @@ public function __construct() * You must use named parameters to construct any parameters with a default value. * * @param DematType|value-of $dematType + * @param list $linkedHolders */ public static function with( ?AdditionalInfo $additionalInfo = null, @@ -95,6 +106,7 @@ public static function with( ?string $dpID = null, ?string $dpName = null, ?Holdings $holdings = null, + ?array $linkedHolders = null, ?float $value = null, ): self { $obj = new self; @@ -102,10 +114,11 @@ public static function with( null !== $additionalInfo && $obj->additionalInfo = $additionalInfo; null !== $boID && $obj->boID = $boID; null !== $clientID && $obj->clientID = $clientID; - null !== $dematType && $obj->dematType = $dematType instanceof DematType ? $dematType->value : $dematType; + null !== $dematType && $obj['dematType'] = $dematType; null !== $dpID && $obj->dpID = $dpID; null !== $dpName && $obj->dpName = $dpName; null !== $holdings && $obj->holdings = $holdings; + null !== $linkedHolders && $obj->linkedHolders = $linkedHolders; null !== $value && $obj->value = $value; return $obj; @@ -152,7 +165,7 @@ public function withClientID(string $clientID): self public function withDematType(DematType|string $dematType): self { $obj = clone $this; - $obj->dematType = $dematType instanceof DematType ? $dematType->value : $dematType; + $obj['dematType'] = $dematType; return $obj; } @@ -187,6 +200,19 @@ public function withHoldings(Holdings $holdings): self return $obj; } + /** + * List of account holders linked to this demat account. + * + * @param list $linkedHolders + */ + public function withLinkedHolders(array $linkedHolders): self + { + $obj = clone $this; + $obj->linkedHolders = $linkedHolders; + + return $obj; + } + /** * Total value of the demat account. */ diff --git a/src/CasParser/UnifiedResponse/DematAccount/AdditionalInfo.php b/src/CasParser/UnifiedResponse/DematAccount/AdditionalInfo.php index c7a8be5..4244d41 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/AdditionalInfo.php +++ b/src/CasParser/UnifiedResponse/DematAccount/AdditionalInfo.php @@ -11,7 +11,7 @@ /** * Additional information specific to the demat account type. * - * @phpstan-type additional_info = array{ + * @phpstan-type AdditionalInfoShape = array{ * boStatus?: string, * boSubStatus?: string, * boType?: string, @@ -24,7 +24,7 @@ */ final class AdditionalInfo implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/DematAccount/Holdings.php b/src/CasParser/UnifiedResponse/DematAccount/Holdings.php index eb3b0d1..fa8713b 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/Holdings.php +++ b/src/CasParser/UnifiedResponse/DematAccount/Holdings.php @@ -14,7 +14,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type holdings_alias = array{ + * @phpstan-type HoldingsShape = array{ * aifs?: list, * corporateBonds?: list, * dematMutualFunds?: list, @@ -24,7 +24,7 @@ */ final class Holdings implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @var list|null $aifs */ diff --git a/src/CasParser/UnifiedResponse/DematAccount/Holdings/Aif.php b/src/CasParser/UnifiedResponse/DematAccount/Holdings/Aif.php index 1df6013..a5ff45a 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/Holdings/Aif.php +++ b/src/CasParser/UnifiedResponse/DematAccount/Holdings/Aif.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type aif_alias = array{ + * @phpstan-type AifShape = array{ * additionalInfo?: mixed, * isin?: string, * name?: string, @@ -19,7 +19,7 @@ */ final class Aif implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/DematAccount/Holdings/CorporateBond.php b/src/CasParser/UnifiedResponse/DematAccount/Holdings/CorporateBond.php index bfb4d84..4c815dc 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/Holdings/CorporateBond.php +++ b/src/CasParser/UnifiedResponse/DematAccount/Holdings/CorporateBond.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type corporate_bond = array{ + * @phpstan-type CorporateBondShape = array{ * additionalInfo?: mixed, * isin?: string, * name?: string, @@ -19,7 +19,7 @@ */ final class CorporateBond implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/DematAccount/Holdings/DematMutualFund.php b/src/CasParser/UnifiedResponse/DematAccount/Holdings/DematMutualFund.php index 36015d7..072a276 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/Holdings/DematMutualFund.php +++ b/src/CasParser/UnifiedResponse/DematAccount/Holdings/DematMutualFund.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type demat_mutual_fund = array{ + * @phpstan-type DematMutualFundShape = array{ * additionalInfo?: mixed, * isin?: string, * name?: string, @@ -19,7 +19,7 @@ */ final class DematMutualFund implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/DematAccount/Holdings/Equity.php b/src/CasParser/UnifiedResponse/DematAccount/Holdings/Equity.php index 0c1b5c2..4ce5c46 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/Holdings/Equity.php +++ b/src/CasParser/UnifiedResponse/DematAccount/Holdings/Equity.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type equity_alias = array{ + * @phpstan-type EquityShape = array{ * additionalInfo?: mixed, * isin?: string, * name?: string, @@ -19,7 +19,7 @@ */ final class Equity implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/DematAccount/Holdings/GovernmentSecurity.php b/src/CasParser/UnifiedResponse/DematAccount/Holdings/GovernmentSecurity.php index cd4249f..be303b1 100644 --- a/src/CasParser/UnifiedResponse/DematAccount/Holdings/GovernmentSecurity.php +++ b/src/CasParser/UnifiedResponse/DematAccount/Holdings/GovernmentSecurity.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type government_security = array{ + * @phpstan-type GovernmentSecurityShape = array{ * additionalInfo?: mixed, * isin?: string, * name?: string, @@ -19,7 +19,7 @@ */ final class GovernmentSecurity implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/DematAccount/LinkedHolder.php b/src/CasParser/UnifiedResponse/DematAccount/LinkedHolder.php new file mode 100644 index 0000000..940d72f --- /dev/null +++ b/src/CasParser/UnifiedResponse/DematAccount/LinkedHolder.php @@ -0,0 +1,72 @@ + */ + use SdkModel; + + /** + * Name of the account holder. + */ + #[Api(optional: true)] + public ?string $name; + + /** + * PAN of the account holder. + */ + #[Api(optional: true)] + public ?string $pan; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(?string $name = null, ?string $pan = null): self + { + $obj = new self; + + null !== $name && $obj->name = $name; + null !== $pan && $obj->pan = $pan; + + return $obj; + } + + /** + * Name of the account holder. + */ + public function withName(string $name): self + { + $obj = clone $this; + $obj->name = $name; + + return $obj; + } + + /** + * PAN of the account holder. + */ + public function withPan(string $pan): self + { + $obj = clone $this; + $obj->pan = $pan; + + return $obj; + } +} diff --git a/src/CasParser/UnifiedResponse/Insurance.php b/src/CasParser/UnifiedResponse/Insurance.php index 2a42859..a068cc5 100644 --- a/src/CasParser/UnifiedResponse/Insurance.php +++ b/src/CasParser/UnifiedResponse/Insurance.php @@ -10,13 +10,13 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type insurance_alias = array{ + * @phpstan-type InsuranceShape = array{ * lifeInsurancePolicies?: list * } */ final class Insurance implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @var list|null $lifeInsurancePolicies */ diff --git a/src/CasParser/UnifiedResponse/Insurance/LifeInsurancePolicy.php b/src/CasParser/UnifiedResponse/Insurance/LifeInsurancePolicy.php index c106c9c..fd935e9 100644 --- a/src/CasParser/UnifiedResponse/Insurance/LifeInsurancePolicy.php +++ b/src/CasParser/UnifiedResponse/Insurance/LifeInsurancePolicy.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type life_insurance_policy = array{ + * @phpstan-type LifeInsurancePolicyShape = array{ * additionalInfo?: mixed, * lifeAssured?: string, * policyName?: string, @@ -23,7 +23,7 @@ */ final class LifeInsurancePolicy implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/Investor.php b/src/CasParser/UnifiedResponse/Investor.php index dd04ddc..679d124 100644 --- a/src/CasParser/UnifiedResponse/Investor.php +++ b/src/CasParser/UnifiedResponse/Investor.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type investor_alias = array{ + * @phpstan-type InvestorShape = array{ * address?: string, * casID?: string, * email?: string, @@ -21,7 +21,7 @@ */ final class Investor implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/Meta.php b/src/CasParser/UnifiedResponse/Meta.php index 7f55cb7..71fca99 100644 --- a/src/CasParser/UnifiedResponse/Meta.php +++ b/src/CasParser/UnifiedResponse/Meta.php @@ -11,7 +11,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type meta_alias = array{ + * @phpstan-type MetaShape = array{ * casType?: value-of, * generatedAt?: \DateTimeInterface, * statementPeriod?: StatementPeriod, @@ -19,7 +19,7 @@ */ final class Meta implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @@ -58,7 +58,7 @@ public static function with( ): self { $obj = new self; - null !== $casType && $obj->casType = $casType instanceof CasType ? $casType->value : $casType; + null !== $casType && $obj['casType'] = $casType; null !== $generatedAt && $obj->generatedAt = $generatedAt; null !== $statementPeriod && $obj->statementPeriod = $statementPeriod; @@ -73,7 +73,7 @@ public static function with( public function withCasType(CasType|string $casType): self { $obj = clone $this; - $obj->casType = $casType instanceof CasType ? $casType->value : $casType; + $obj['casType'] = $casType; return $obj; } diff --git a/src/CasParser/UnifiedResponse/Meta/StatementPeriod.php b/src/CasParser/UnifiedResponse/Meta/StatementPeriod.php index ebeb0f2..5fc9522 100644 --- a/src/CasParser/UnifiedResponse/Meta/StatementPeriod.php +++ b/src/CasParser/UnifiedResponse/Meta/StatementPeriod.php @@ -9,13 +9,13 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type statement_period = array{ + * @phpstan-type StatementPeriodShape = array{ * from?: \DateTimeInterface, to?: \DateTimeInterface * } */ final class StatementPeriod implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/MutualFund.php b/src/CasParser/UnifiedResponse/MutualFund.php index 2f1da0c..77d6544 100644 --- a/src/CasParser/UnifiedResponse/MutualFund.php +++ b/src/CasParser/UnifiedResponse/MutualFund.php @@ -5,16 +5,18 @@ namespace CasParser\CasParser\UnifiedResponse; use CasParser\CasParser\UnifiedResponse\MutualFund\AdditionalInfo; +use CasParser\CasParser\UnifiedResponse\MutualFund\LinkedHolder; use CasParser\CasParser\UnifiedResponse\MutualFund\Scheme; use CasParser\Core\Attributes\Api; use CasParser\Core\Concerns\SdkModel; use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type mutual_fund = array{ + * @phpstan-type MutualFundShape = array{ * additionalInfo?: AdditionalInfo, * amc?: string, * folioNumber?: string, + * linkedHolders?: list, * registrar?: string, * schemes?: list, * value?: float, @@ -22,7 +24,7 @@ */ final class MutualFund implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @@ -43,6 +45,14 @@ final class MutualFund implements BaseModel #[Api('folio_number', optional: true)] public ?string $folioNumber; + /** + * List of account holders linked to this mutual fund folio. + * + * @var list|null $linkedHolders + */ + #[Api('linked_holders', list: LinkedHolder::class, optional: true)] + public ?array $linkedHolders; + /** * Registrar and Transfer Agent name. */ @@ -69,12 +79,14 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * + * @param list $linkedHolders * @param list $schemes */ public static function with( ?AdditionalInfo $additionalInfo = null, ?string $amc = null, ?string $folioNumber = null, + ?array $linkedHolders = null, ?string $registrar = null, ?array $schemes = null, ?float $value = null, @@ -84,6 +96,7 @@ public static function with( null !== $additionalInfo && $obj->additionalInfo = $additionalInfo; null !== $amc && $obj->amc = $amc; null !== $folioNumber && $obj->folioNumber = $folioNumber; + null !== $linkedHolders && $obj->linkedHolders = $linkedHolders; null !== $registrar && $obj->registrar = $registrar; null !== $schemes && $obj->schemes = $schemes; null !== $value && $obj->value = $value; @@ -124,6 +137,19 @@ public function withFolioNumber(string $folioNumber): self return $obj; } + /** + * List of account holders linked to this mutual fund folio. + * + * @param list $linkedHolders + */ + public function withLinkedHolders(array $linkedHolders): self + { + $obj = clone $this; + $obj->linkedHolders = $linkedHolders; + + return $obj; + } + /** * Registrar and Transfer Agent name. */ diff --git a/src/CasParser/UnifiedResponse/MutualFund/AdditionalInfo.php b/src/CasParser/UnifiedResponse/MutualFund/AdditionalInfo.php index b79ad23..dfe2dac 100644 --- a/src/CasParser/UnifiedResponse/MutualFund/AdditionalInfo.php +++ b/src/CasParser/UnifiedResponse/MutualFund/AdditionalInfo.php @@ -11,13 +11,13 @@ /** * Additional folio information. * - * @phpstan-type additional_info = array{ + * @phpstan-type AdditionalInfoShape = array{ * kyc?: string, pan?: string, pankyc?: string * } */ final class AdditionalInfo implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/MutualFund/LinkedHolder.php b/src/CasParser/UnifiedResponse/MutualFund/LinkedHolder.php new file mode 100644 index 0000000..ba4a9f6 --- /dev/null +++ b/src/CasParser/UnifiedResponse/MutualFund/LinkedHolder.php @@ -0,0 +1,72 @@ + */ + use SdkModel; + + /** + * Name of the account holder. + */ + #[Api(optional: true)] + public ?string $name; + + /** + * PAN of the account holder. + */ + #[Api(optional: true)] + public ?string $pan; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(?string $name = null, ?string $pan = null): self + { + $obj = new self; + + null !== $name && $obj->name = $name; + null !== $pan && $obj->pan = $pan; + + return $obj; + } + + /** + * Name of the account holder. + */ + public function withName(string $name): self + { + $obj = clone $this; + $obj->name = $name; + + return $obj; + } + + /** + * PAN of the account holder. + */ + public function withPan(string $pan): self + { + $obj = clone $this; + $obj->pan = $pan; + + return $obj; + } +} diff --git a/src/CasParser/UnifiedResponse/MutualFund/Scheme.php b/src/CasParser/UnifiedResponse/MutualFund/Scheme.php index 8775dbb..ec58b72 100644 --- a/src/CasParser/UnifiedResponse/MutualFund/Scheme.php +++ b/src/CasParser/UnifiedResponse/MutualFund/Scheme.php @@ -13,7 +13,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type scheme_alias = array{ + * @phpstan-type SchemeShape = array{ * additionalInfo?: AdditionalInfo, * cost?: float, * gain?: Gain, @@ -29,7 +29,7 @@ */ final class Scheme implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @@ -134,7 +134,7 @@ public static function with( null !== $nav && $obj->nav = $nav; null !== $nominees && $obj->nominees = $nominees; null !== $transactions && $obj->transactions = $transactions; - null !== $type && $obj->type = $type instanceof Type ? $type->value : $type; + null !== $type && $obj['type'] = $type; null !== $units && $obj->units = $units; null !== $value && $obj->value = $value; @@ -236,7 +236,7 @@ public function withTransactions(array $transactions): self public function withType(Type|string $type): self { $obj = clone $this; - $obj->type = $type instanceof Type ? $type->value : $type; + $obj['type'] = $type; return $obj; } diff --git a/src/CasParser/UnifiedResponse/MutualFund/Scheme/AdditionalInfo.php b/src/CasParser/UnifiedResponse/MutualFund/Scheme/AdditionalInfo.php index e5f16cd..383c960 100644 --- a/src/CasParser/UnifiedResponse/MutualFund/Scheme/AdditionalInfo.php +++ b/src/CasParser/UnifiedResponse/MutualFund/Scheme/AdditionalInfo.php @@ -11,7 +11,7 @@ /** * Additional information specific to the scheme. * - * @phpstan-type additional_info = array{ + * @phpstan-type AdditionalInfoShape = array{ * advisor?: string, * amfi?: string, * closeUnits?: float, @@ -21,7 +21,7 @@ */ final class AdditionalInfo implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/MutualFund/Scheme/Gain.php b/src/CasParser/UnifiedResponse/MutualFund/Scheme/Gain.php index 8006cfa..94cac52 100644 --- a/src/CasParser/UnifiedResponse/MutualFund/Scheme/Gain.php +++ b/src/CasParser/UnifiedResponse/MutualFund/Scheme/Gain.php @@ -9,11 +9,11 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type gain_alias = array{absolute?: float, percentage?: float} + * @phpstan-type GainShape = array{absolute?: float, percentage?: float} */ final class Gain implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/MutualFund/Scheme/Transaction.php b/src/CasParser/UnifiedResponse/MutualFund/Scheme/Transaction.php index 0ea64d4..331458b 100644 --- a/src/CasParser/UnifiedResponse/MutualFund/Scheme/Transaction.php +++ b/src/CasParser/UnifiedResponse/MutualFund/Scheme/Transaction.php @@ -9,7 +9,7 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type transaction_alias = array{ + * @phpstan-type TransactionShape = array{ * amount?: float, * balance?: float, * date?: \DateTimeInterface, @@ -22,7 +22,7 @@ */ final class Transaction implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/Np.php b/src/CasParser/UnifiedResponse/Np.php new file mode 100644 index 0000000..666f586 --- /dev/null +++ b/src/CasParser/UnifiedResponse/Np.php @@ -0,0 +1,164 @@ +, + * linkedHolders?: list, + * pran?: string, + * value?: float, + * } + */ +final class Np implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Additional information specific to the NPS account. + */ + #[Api('additional_info', optional: true)] + public mixed $additionalInfo; + + /** + * Central Record Keeping Agency name. + */ + #[Api(optional: true)] + public ?string $cra; + + /** @var list|null $funds */ + #[Api(list: Fund::class, optional: true)] + public ?array $funds; + + /** + * List of account holders linked to this NPS account. + * + * @var list|null $linkedHolders + */ + #[Api('linked_holders', list: LinkedHolder::class, optional: true)] + public ?array $linkedHolders; + + /** + * Permanent Retirement Account Number (PRAN). + */ + #[Api(optional: true)] + public ?string $pran; + + /** + * Total value of the NPS account. + */ + #[Api(optional: true)] + public ?float $value; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param list $funds + * @param list $linkedHolders + */ + public static function with( + mixed $additionalInfo = null, + ?string $cra = null, + ?array $funds = null, + ?array $linkedHolders = null, + ?string $pran = null, + ?float $value = null, + ): self { + $obj = new self; + + null !== $additionalInfo && $obj->additionalInfo = $additionalInfo; + null !== $cra && $obj->cra = $cra; + null !== $funds && $obj->funds = $funds; + null !== $linkedHolders && $obj->linkedHolders = $linkedHolders; + null !== $pran && $obj->pran = $pran; + null !== $value && $obj->value = $value; + + return $obj; + } + + /** + * Additional information specific to the NPS account. + */ + public function withAdditionalInfo(mixed $additionalInfo): self + { + $obj = clone $this; + $obj->additionalInfo = $additionalInfo; + + return $obj; + } + + /** + * Central Record Keeping Agency name. + */ + public function withCra(string $cra): self + { + $obj = clone $this; + $obj->cra = $cra; + + return $obj; + } + + /** + * @param list $funds + */ + public function withFunds(array $funds): self + { + $obj = clone $this; + $obj->funds = $funds; + + return $obj; + } + + /** + * List of account holders linked to this NPS account. + * + * @param list $linkedHolders + */ + public function withLinkedHolders(array $linkedHolders): self + { + $obj = clone $this; + $obj->linkedHolders = $linkedHolders; + + return $obj; + } + + /** + * Permanent Retirement Account Number (PRAN). + */ + public function withPran(string $pran): self + { + $obj = clone $this; + $obj->pran = $pran; + + return $obj; + } + + /** + * Total value of the NPS account. + */ + public function withValue(float $value): self + { + $obj = clone $this; + $obj->value = $value; + + return $obj; + } +} diff --git a/src/CasParser/UnifiedResponse/Np/Fund.php b/src/CasParser/UnifiedResponse/Np/Fund.php new file mode 100644 index 0000000..727ad14 --- /dev/null +++ b/src/CasParser/UnifiedResponse/Np/Fund.php @@ -0,0 +1,158 @@ + */ + use SdkModel; + + /** + * Additional information specific to the NPS fund. + */ + #[Api('additional_info', optional: true)] + public ?AdditionalInfo $additionalInfo; + + /** + * Cost of investment. + */ + #[Api(optional: true)] + public ?float $cost; + + /** + * Name of the NPS fund. + */ + #[Api(optional: true)] + public ?string $name; + + /** + * Net Asset Value per unit. + */ + #[Api(optional: true)] + public ?float $nav; + + /** + * Number of units held. + */ + #[Api(optional: true)] + public ?float $units; + + /** + * Current market value of the holding. + */ + #[Api(optional: true)] + public ?float $value; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?AdditionalInfo $additionalInfo = null, + ?float $cost = null, + ?string $name = null, + ?float $nav = null, + ?float $units = null, + ?float $value = null, + ): self { + $obj = new self; + + null !== $additionalInfo && $obj->additionalInfo = $additionalInfo; + null !== $cost && $obj->cost = $cost; + null !== $name && $obj->name = $name; + null !== $nav && $obj->nav = $nav; + null !== $units && $obj->units = $units; + null !== $value && $obj->value = $value; + + return $obj; + } + + /** + * Additional information specific to the NPS fund. + */ + public function withAdditionalInfo(AdditionalInfo $additionalInfo): self + { + $obj = clone $this; + $obj->additionalInfo = $additionalInfo; + + return $obj; + } + + /** + * Cost of investment. + */ + public function withCost(float $cost): self + { + $obj = clone $this; + $obj->cost = $cost; + + return $obj; + } + + /** + * Name of the NPS fund. + */ + public function withName(string $name): self + { + $obj = clone $this; + $obj->name = $name; + + return $obj; + } + + /** + * Net Asset Value per unit. + */ + public function withNav(float $nav): self + { + $obj = clone $this; + $obj->nav = $nav; + + return $obj; + } + + /** + * Number of units held. + */ + public function withUnits(float $units): self + { + $obj = clone $this; + $obj->units = $units; + + return $obj; + } + + /** + * Current market value of the holding. + */ + public function withValue(float $value): self + { + $obj = clone $this; + $obj->value = $value; + + return $obj; + } +} diff --git a/src/CasParser/UnifiedResponse/Np/Fund/AdditionalInfo.php b/src/CasParser/UnifiedResponse/Np/Fund/AdditionalInfo.php new file mode 100644 index 0000000..79a16db --- /dev/null +++ b/src/CasParser/UnifiedResponse/Np/Fund/AdditionalInfo.php @@ -0,0 +1,76 @@ + */ + use SdkModel; + + /** + * Fund manager name. + */ + #[Api(optional: true)] + public ?string $manager; + + /** + * NPS tier (Tier I or Tier II). + */ + #[Api(nullable: true, optional: true)] + public ?float $tier; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?string $manager = null, + ?float $tier = null + ): self { + $obj = new self; + + null !== $manager && $obj->manager = $manager; + null !== $tier && $obj->tier = $tier; + + return $obj; + } + + /** + * Fund manager name. + */ + public function withManager(string $manager): self + { + $obj = clone $this; + $obj->manager = $manager; + + return $obj; + } + + /** + * NPS tier (Tier I or Tier II). + */ + public function withTier(?float $tier): self + { + $obj = clone $this; + $obj->tier = $tier; + + return $obj; + } +} diff --git a/src/CasParser/UnifiedResponse/Np/LinkedHolder.php b/src/CasParser/UnifiedResponse/Np/LinkedHolder.php new file mode 100644 index 0000000..07b6856 --- /dev/null +++ b/src/CasParser/UnifiedResponse/Np/LinkedHolder.php @@ -0,0 +1,72 @@ + */ + use SdkModel; + + /** + * Name of the account holder. + */ + #[Api(optional: true)] + public ?string $name; + + /** + * PAN of the account holder. + */ + #[Api(optional: true)] + public ?string $pan; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(?string $name = null, ?string $pan = null): self + { + $obj = new self; + + null !== $name && $obj->name = $name; + null !== $pan && $obj->pan = $pan; + + return $obj; + } + + /** + * Name of the account holder. + */ + public function withName(string $name): self + { + $obj = clone $this; + $obj->name = $name; + + return $obj; + } + + /** + * PAN of the account holder. + */ + public function withPan(string $pan): self + { + $obj = clone $this; + $obj->pan = $pan; + + return $obj; + } +} diff --git a/src/CasParser/UnifiedResponse/Summary.php b/src/CasParser/UnifiedResponse/Summary.php index 6b32295..99771b2 100644 --- a/src/CasParser/UnifiedResponse/Summary.php +++ b/src/CasParser/UnifiedResponse/Summary.php @@ -10,11 +10,11 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type summary_alias = array{accounts?: Accounts, totalValue?: float} + * @phpstan-type SummaryShape = array{accounts?: Accounts, totalValue?: float} */ final class Summary implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; #[Api(optional: true)] diff --git a/src/CasParser/UnifiedResponse/Summary/Accounts.php b/src/CasParser/UnifiedResponse/Summary/Accounts.php index 82b1f21..ce5d3ee 100644 --- a/src/CasParser/UnifiedResponse/Summary/Accounts.php +++ b/src/CasParser/UnifiedResponse/Summary/Accounts.php @@ -7,18 +7,19 @@ use CasParser\CasParser\UnifiedResponse\Summary\Accounts\Demat; use CasParser\CasParser\UnifiedResponse\Summary\Accounts\Insurance; use CasParser\CasParser\UnifiedResponse\Summary\Accounts\MutualFunds; +use CasParser\CasParser\UnifiedResponse\Summary\Accounts\Nps; use CasParser\Core\Attributes\Api; use CasParser\Core\Concerns\SdkModel; use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type accounts_alias = array{ - * demat?: Demat, insurance?: Insurance, mutualFunds?: MutualFunds + * @phpstan-type AccountsShape = array{ + * demat?: Demat, insurance?: Insurance, mutualFunds?: MutualFunds, nps?: Nps * } */ final class Accounts implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; #[Api(optional: true)] @@ -30,6 +31,9 @@ final class Accounts implements BaseModel #[Api('mutual_funds', optional: true)] public ?MutualFunds $mutualFunds; + #[Api(optional: true)] + public ?Nps $nps; + public function __construct() { $this->initialize(); @@ -44,12 +48,14 @@ public static function with( ?Demat $demat = null, ?Insurance $insurance = null, ?MutualFunds $mutualFunds = null, + ?Nps $nps = null, ): self { $obj = new self; null !== $demat && $obj->demat = $demat; null !== $insurance && $obj->insurance = $insurance; null !== $mutualFunds && $obj->mutualFunds = $mutualFunds; + null !== $nps && $obj->nps = $nps; return $obj; } @@ -77,4 +83,12 @@ public function withMutualFunds(MutualFunds $mutualFunds): self return $obj; } + + public function withNps(Nps $nps): self + { + $obj = clone $this; + $obj->nps = $nps; + + return $obj; + } } diff --git a/src/CasParser/UnifiedResponse/Summary/Accounts/Demat.php b/src/CasParser/UnifiedResponse/Summary/Accounts/Demat.php index 50165c2..77e37ca 100644 --- a/src/CasParser/UnifiedResponse/Summary/Accounts/Demat.php +++ b/src/CasParser/UnifiedResponse/Summary/Accounts/Demat.php @@ -9,11 +9,11 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type demat_alias = array{count?: int, totalValue?: float} + * @phpstan-type DematShape = array{count?: int, totalValue?: float} */ final class Demat implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/Summary/Accounts/Insurance.php b/src/CasParser/UnifiedResponse/Summary/Accounts/Insurance.php index a14d733..ec2d5b4 100644 --- a/src/CasParser/UnifiedResponse/Summary/Accounts/Insurance.php +++ b/src/CasParser/UnifiedResponse/Summary/Accounts/Insurance.php @@ -9,11 +9,11 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type insurance_alias = array{count?: int, totalValue?: float} + * @phpstan-type InsuranceShape = array{count?: int, totalValue?: float} */ final class Insurance implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/Summary/Accounts/MutualFunds.php b/src/CasParser/UnifiedResponse/Summary/Accounts/MutualFunds.php index dc2f0c0..08bdf24 100644 --- a/src/CasParser/UnifiedResponse/Summary/Accounts/MutualFunds.php +++ b/src/CasParser/UnifiedResponse/Summary/Accounts/MutualFunds.php @@ -9,11 +9,11 @@ use CasParser\Core\Contracts\BaseModel; /** - * @phpstan-type mutual_funds = array{count?: int, totalValue?: float} + * @phpstan-type MutualFundsShape = array{count?: int, totalValue?: float} */ final class MutualFunds implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** diff --git a/src/CasParser/UnifiedResponse/Summary/Accounts/Nps.php b/src/CasParser/UnifiedResponse/Summary/Accounts/Nps.php new file mode 100644 index 0000000..ce9d152 --- /dev/null +++ b/src/CasParser/UnifiedResponse/Summary/Accounts/Nps.php @@ -0,0 +1,74 @@ + */ + use SdkModel; + + /** + * Number of NPS accounts. + */ + #[Api(optional: true)] + public ?int $count; + + /** + * Total value of NPS accounts. + */ + #[Api('total_value', optional: true)] + public ?float $totalValue; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?int $count = null, + ?float $totalValue = null + ): self { + $obj = new self; + + null !== $count && $obj->count = $count; + null !== $totalValue && $obj->totalValue = $totalValue; + + return $obj; + } + + /** + * Number of NPS accounts. + */ + public function withCount(int $count): self + { + $obj = clone $this; + $obj->count = $count; + + return $obj; + } + + /** + * Total value of NPS accounts. + */ + public function withTotalValue(float $totalValue): self + { + $obj = clone $this; + $obj->totalValue = $totalValue; + + return $obj; + } +} diff --git a/src/Client.php b/src/Client.php index 947f3cc..942b577 100644 --- a/src/Client.php +++ b/src/Client.php @@ -28,7 +28,7 @@ public function __construct(?string $apiKey = null, ?string $baseUrl = null) { $this->apiKey = (string) ($apiKey ?? getenv('CAS_PARSER_API_KEY')); - $base = $baseUrl ?? getenv( + $baseUrl ??= getenv( 'CAS_PARSER_BASE_URL' ) ?: 'https://portfolio-parser.api.casparser.in'; @@ -40,10 +40,20 @@ public function __construct(?string $apiKey = null, ?string $baseUrl = null) ); parent::__construct( + // x-release-please-start-version headers: [ - 'Content-Type' => 'application/json', 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'User-Agent' => sprintf('CAS Parser/PHP %s', '0.3.0'), + 'X-Stainless-Lang' => 'php', + 'X-Stainless-Package-Version' => '0.3.0', + 'X-Stainless-OS' => $this->getNormalizedOS(), + 'X-Stainless-Arch' => $this->getNormalizedArchitecture(), + 'X-Stainless-Runtime' => 'php', + 'X-Stainless-Runtime-Version' => phpversion(), ], - baseUrl: $base, + // x-release-please-end + baseUrl: $baseUrl, options: $options, ); @@ -54,6 +64,6 @@ public function __construct(?string $apiKey = null, ?string $baseUrl = null) /** @return array */ protected function authHeaders(): array { - return ['x-api-key' => $this->apiKey]; + return $this->apiKey ? ['x-api-key' => $this->apiKey] : []; } } diff --git a/src/Core/BaseClient.php b/src/Core/BaseClient.php index cae68a4..e907bda 100644 --- a/src/Core/BaseClient.php +++ b/src/Core/BaseClient.php @@ -29,7 +29,7 @@ * body: mixed, * } */ -class BaseClient +abstract class BaseClient { protected UriInterface $baseUrl; @@ -77,14 +77,11 @@ public function request( // @phpstan-ignore-next-line $rsp = $this->sendRequest($opts, req: $request, data: $body, redirectCount: 0, retryCount: 0); - $decoded = Util::decodeContent($rsp); - if (!is_null($stream)) { return new $stream( convert: $convert, request: $request, - response: $rsp, - stream: $decoded + response: $rsp ); } @@ -93,22 +90,69 @@ public function request( convert: $convert, client: $this, request: $req, + response: $rsp, options: $opts, - data: $decoded, ); } if (!is_null($convert)) { - return Conversion::coerce($convert, value: $decoded); + return Conversion::coerceResponse($convert, response: $rsp); } - return $decoded; + return Util::decodeContent($rsp); } /** @return array */ - protected function authHeaders(): array + abstract protected function authHeaders(): array; + + protected function getNormalizedOS(): string { - return []; + $os = strtolower(PHP_OS_FAMILY); + + switch ($os) { + case 'windows': + return 'Windows'; + + case 'darwin': + return 'MacOS'; + + case 'linux': + return 'Linux'; + + case 'bsd': + case 'freebsd': + case 'openbsd': + return 'BSD'; + + case 'solaris': + return 'Solaris'; + + case 'unix': + case 'unknown': + return 'Unknown'; + + default: + return 'Other:'.$os; + } + } + + protected function getNormalizedArchitecture(): string + { + $arch = php_uname('m'); + if (false !== strpos($arch, 'x86_64') || false !== strpos($arch, 'amd64')) { + return 'x64'; + } + if (false !== strpos($arch, 'i386') || false !== strpos($arch, 'i686')) { + return 'x32'; + } + if (false !== strpos($arch, 'aarch64') || false !== strpos($arch, 'arm64')) { + return 'arm64'; + } + if (false !== strpos($arch, 'arm')) { + return 'arm'; + } + + return 'unknown'; } /** @@ -244,6 +288,8 @@ protected function sendRequest( ): ResponseInterface { assert(null !== $opts->streamFactory && null !== $opts->transporter); + $req = $req->withHeader('X-Stainless-Retry-Count', strval($retryCount)); + $req = Util::withSetBody($opts->streamFactory, req: $req, body: $data); $rsp = null; @@ -270,7 +316,7 @@ protected function sendRequest( } if ($code >= 400 || is_null($rsp)) { - if ($this->shouldRetry($opts, retryCount: $retryCount, rsp: $rsp)) { + if (!$this->shouldRetry($opts, retryCount: $retryCount, rsp: $rsp)) { $exn = is_null($rsp) ? new APIConnectionException($req, previous: $err) : APIStatusException::from(request: $req, response: $rsp); throw $exn; diff --git a/src/Core/Concerns/SdkModel.php b/src/Core/Concerns/SdkModel.php index 27f095b..3f0e929 100644 --- a/src/Core/Concerns/SdkModel.php +++ b/src/Core/Concerns/SdkModel.php @@ -32,9 +32,9 @@ trait SdkModel */ public function __serialize(): array { - $rows = [...Util::get_object_vars($this), ...$this->_data]; // @phpstan-ignore-line + $properties = $this->toProperties(); // @phpstan-ignore-line - return array_map(static fn ($v) => self::serialize($v), array: $rows); + return array_map(static fn ($v) => self::serialize($v), array: $properties); } /** @@ -98,11 +98,13 @@ public function __get(string $key): mixed } /** + * @internal + * * @return Shape */ - public function toArray(): array + public function toProperties(): array { - return $this->__serialize(); // @phpstan-ignore-line + return [...Util::get_object_vars($this), ...$this->_data]; // @phpstan-ignore-line } /** @@ -257,7 +259,7 @@ private function initialize(): void private static function serialize(mixed $value): mixed { if ($value instanceof BaseModel) { - return $value->toArray(); + return $value->toProperties(); } if (is_array($value)) { diff --git a/src/Core/Concerns/SdkResponse.php b/src/Core/Concerns/SdkResponse.php new file mode 100644 index 0000000..95bf61f --- /dev/null +++ b/src/Core/Concerns/SdkResponse.php @@ -0,0 +1,29 @@ +_rawResponse = $response; + $instance->__unserialize(Util::decodeContent($response)); // @phpstan-ignore-line + + return $instance; + } + + public function getRawResponse(): ?ResponseInterface + { + return $this->_rawResponse; + } +} diff --git a/src/Core/Contracts/BaseModel.php b/src/Core/Contracts/BaseModel.php index a6b38d2..1938411 100644 --- a/src/Core/Contracts/BaseModel.php +++ b/src/Core/Contracts/BaseModel.php @@ -14,5 +14,5 @@ interface BaseModel extends \ArrayAccess, \JsonSerializable, \Stringable, ConverterSource { /** @return array */ - public function toArray(): array; + public function toProperties(): array; } diff --git a/src/Core/Contracts/BasePage.php b/src/Core/Contracts/BasePage.php index 40eecd6..c997b93 100644 --- a/src/Core/Contracts/BasePage.php +++ b/src/Core/Contracts/BasePage.php @@ -8,6 +8,7 @@ use CasParser\Core\Conversion\Contracts\Converter; use CasParser\Core\Conversion\Contracts\ConverterSource; use CasParser\RequestOptions; +use Psr\Http\Message\ResponseInterface; /** * @internal @@ -30,7 +31,7 @@ public function __construct( Client $client, array $request, RequestOptions $options, - mixed $data, + ResponseInterface $response, ); public function hasNextPage(): bool; diff --git a/src/Core/Contracts/BaseStream.php b/src/Core/Contracts/BaseStream.php index 26a9dd7..dd75235 100644 --- a/src/Core/Contracts/BaseStream.php +++ b/src/Core/Contracts/BaseStream.php @@ -18,14 +18,10 @@ */ interface BaseStream extends \IteratorAggregate { - /** - * @param \Generator $stream - */ public function __construct( Converter|ConverterSource|string $convert, RequestInterface $request, ResponseInterface $response, - \Generator $stream, ); /** diff --git a/src/Core/Conversion.php b/src/Core/Conversion.php index e8c605e..697b753 100644 --- a/src/Core/Conversion.php +++ b/src/Core/Conversion.php @@ -7,8 +7,13 @@ use CasParser\Core\Conversion\CoerceState; use CasParser\Core\Conversion\Contracts\Converter; use CasParser\Core\Conversion\Contracts\ConverterSource; +use CasParser\Core\Conversion\Contracts\ResponseConverter; use CasParser\Core\Conversion\DumpState; +use Psr\Http\Message\ResponseInterface; +/** + * @internal + */ final class Conversion { public static function dump_unknown(mixed $value, DumpState $state): mixed @@ -38,6 +43,15 @@ public static function dump_unknown(mixed $value, DumpState $state): mixed return $value; } + public static function coerceResponse(Converter|ConverterSource|string $target, ResponseInterface $response): mixed + { + if (is_a($target, ResponseConverter::class, allow_string: true)) { + return $target::fromResponse($response); + } + + return self::coerce($target, Util::decodeContent($response)); + } + public static function coerce(Converter|ConverterSource|string $target, mixed $value, CoerceState $state = new CoerceState): mixed { if ($value instanceof $target) { diff --git a/src/Core/Conversion/Contracts/ResponseConverter.php b/src/Core/Conversion/Contracts/ResponseConverter.php new file mode 100644 index 0000000..69ad591 --- /dev/null +++ b/src/Core/Conversion/Contracts/ResponseConverter.php @@ -0,0 +1,18 @@ +toArray(); + $value = $value->toProperties(); } if (is_array($value)) { diff --git a/src/Core/Implementation/HasRawResponse.php b/src/Core/Implementation/HasRawResponse.php deleted file mode 100644 index d3ffd67..0000000 --- a/src/Core/Implementation/HasRawResponse.php +++ /dev/null @@ -1,10 +0,0 @@ - $o instanceof self ? $o->toArray() : $o ?? [], array: $options); + $parsed = array_map(static fn ($o) => $o instanceof self ? $o->toProperties() : $o ?? [], array: $options); return self::with(...array_merge(...$parsed)); // @phpstan-ignore-line } diff --git a/src/ServiceContracts/CasGeneratorContract.php b/src/ServiceContracts/CasGeneratorContract.php index 240aad8..a706431 100644 --- a/src/ServiceContracts/CasGeneratorContract.php +++ b/src/ServiceContracts/CasGeneratorContract.php @@ -7,7 +7,6 @@ use CasParser\CasGenerator\CasGeneratorGenerateCasParams\CasAuthority; use CasParser\CasGenerator\CasGeneratorGenerateCasResponse; use CasParser\Core\Exceptions\APIException; -use CasParser\Core\Implementation\HasRawResponse; use CasParser\RequestOptions; use const CasParser\Core\OMIT as omit; @@ -24,8 +23,6 @@ interface CasGeneratorContract * @param CasAuthority|value-of $casAuthority CAS authority to generate the document from (currently only kfintech is supported) * @param string $panNo PAN number (optional for some CAS authorities) * - * @return CasGeneratorGenerateCasResponse - * * @throws APIException */ public function generateCas( @@ -43,8 +40,6 @@ public function generateCas( * * @param array $params * - * @return CasGeneratorGenerateCasResponse - * * @throws APIException */ public function generateCasRaw( diff --git a/src/ServiceContracts/CasParserContract.php b/src/ServiceContracts/CasParserContract.php index c21836f..977b15d 100644 --- a/src/ServiceContracts/CasParserContract.php +++ b/src/ServiceContracts/CasParserContract.php @@ -6,7 +6,6 @@ use CasParser\CasParser\UnifiedResponse; use CasParser\Core\Exceptions\APIException; -use CasParser\Core\Implementation\HasRawResponse; use CasParser\RequestOptions; use const CasParser\Core\OMIT as omit; @@ -20,8 +19,6 @@ interface CasParserContract * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function camsKfintech( @@ -36,8 +33,6 @@ public function camsKfintech( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function camsKfintechRaw( @@ -52,8 +47,6 @@ public function camsKfintechRaw( * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function cdsl( @@ -68,8 +61,6 @@ public function cdsl( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function cdslRaw( @@ -84,8 +75,6 @@ public function cdslRaw( * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function nsdl( @@ -100,8 +89,6 @@ public function nsdl( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function nsdlRaw( @@ -116,8 +103,6 @@ public function nsdlRaw( * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function smartParse( @@ -132,8 +117,6 @@ public function smartParse( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function smartParseRaw( diff --git a/src/Services/CasGeneratorService.php b/src/Services/CasGeneratorService.php index c7d2e8e..1a4227e 100644 --- a/src/Services/CasGeneratorService.php +++ b/src/Services/CasGeneratorService.php @@ -9,7 +9,6 @@ use CasParser\CasGenerator\CasGeneratorGenerateCasResponse; use CasParser\Client; use CasParser\Core\Exceptions\APIException; -use CasParser\Core\Implementation\HasRawResponse; use CasParser\RequestOptions; use CasParser\ServiceContracts\CasGeneratorContract; @@ -35,8 +34,6 @@ public function __construct(private Client $client) {} * @param CasAuthority|value-of $casAuthority CAS authority to generate the document from (currently only kfintech is supported) * @param string $panNo PAN number (optional for some CAS authorities) * - * @return CasGeneratorGenerateCasResponse - * * @throws APIException */ public function generateCas( @@ -65,8 +62,6 @@ public function generateCas( * * @param array $params * - * @return CasGeneratorGenerateCasResponse - * * @throws APIException */ public function generateCasRaw( diff --git a/src/Services/CasParserService.php b/src/Services/CasParserService.php index 8c2adff..b0a900d 100644 --- a/src/Services/CasParserService.php +++ b/src/Services/CasParserService.php @@ -11,7 +11,6 @@ use CasParser\CasParser\UnifiedResponse; use CasParser\Client; use CasParser\Core\Exceptions\APIException; -use CasParser\Core\Implementation\HasRawResponse; use CasParser\RequestOptions; use CasParser\ServiceContracts\CasParserContract; @@ -34,8 +33,6 @@ public function __construct(private Client $client) {} * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function camsKfintech( @@ -56,8 +53,6 @@ public function camsKfintech( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function camsKfintechRaw( @@ -89,8 +84,6 @@ public function camsKfintechRaw( * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function cdsl( @@ -111,8 +104,6 @@ public function cdsl( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function cdslRaw( @@ -144,8 +135,6 @@ public function cdslRaw( * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function nsdl( @@ -166,8 +155,6 @@ public function nsdl( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function nsdlRaw( @@ -199,8 +186,6 @@ public function nsdlRaw( * @param string $pdfFile Base64 encoded CAS PDF file * @param string $pdfURL URL to the CAS PDF file * - * @return UnifiedResponse - * * @throws APIException */ public function smartParse( @@ -221,8 +206,6 @@ public function smartParse( * * @param array $params * - * @return UnifiedResponse - * * @throws APIException */ public function smartParseRaw(