{"id":19136911,"url":"https://github.com/xactsystems/cast","last_synced_at":"2026-03-03T06:37:14.391Z","repository":{"id":255351635,"uuid":"848827412","full_name":"XactSystems/cast","owner":"XactSystems","description":"Safely cast PHP mixed values to scalar types, DateTime or null.","archived":false,"fork":false,"pushed_at":"2024-08-29T12:33:03.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-28T03:30:25.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/XactSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-28T13:32:26.000Z","updated_at":"2024-08-29T12:31:11.000Z","dependencies_parsed_at":"2024-08-29T13:11:51.951Z","dependency_job_id":"3b22b5f1-4cf4-40f0-9fc0-940cf0ed5286","html_url":"https://github.com/XactSystems/cast","commit_stats":null,"previous_names":["xactsystems/cast"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/XactSystems/cast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Fcast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Fcast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Fcast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Fcast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XactSystems","download_url":"https://codeload.github.com/XactSystems/cast/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Fcast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30034157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T06:09:21.518Z","status":"ssl_error","status_checked_at":"2026-03-03T06:08:47.858Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T06:35:50.110Z","updated_at":"2026-03-03T06:37:14.366Z","avatar_url":"https://github.com/XactSystems.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cast\nSafely cast mixed values to scalar types or null.\n\nUsed to provide safe casts of scalar values and DateTime in PHP, avoiding PHPSTAN issues when casting 'mixed' values that do not convert as expected.\n\nFor a better understanding of the problem, take a look at the PHPSTAN issue 9295:\nhttps://github.com/phpstan/phpstan/issues/9295\n\n\n## Documentation\n-------------\n### Installation\n```bash\ncomposer require xactsystems/cast\n```\n\n### Usage\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace Xact\\Cast;\n\nuse DateTime;\nuse Xact\\Cast\\Cast;\n\nclass Test\n{\n    protected int $myInt;\n    protected ?int $myNullInt;\n    protected float $myFloat;\n    protected ?float $myNullFloat;\n    protected string $myString;\n    protected ?string $myNullString;\n    protected bool $myBool;\n    protected ?bool $myNullBool;\n    protected ?array $myNullArray;\n    protected ?object $myNullObject;\n    protected ?DateTime $myNullDateTime;\n\n    public function testCast(mixed $value, mixed $nullValue = null): void\n    {\n        $this-\u003emyInt = Cast::intval($value);\n        $this-\u003emyNullInt = Cast::nullInt($nullValue);\n        $this-\u003emyFloat = Cast::nullFloat($value);\n        $this-\u003emyNullFloat = Cast::nullFloat($nullValue);\n        $this-\u003emyString = Cast::strval($value);\n        $this-\u003emyNullString = Cast::nullString($nullValue);\n        $this-\u003emyBool = Cast::boolval($value);\n        $this-\u003emyNullBool = Cast::nullBool($nullValue);\n        $this-\u003emyNullArray = Cast::nullArray($nullValue);\n        $this-\u003emyNullObject = Cast::nullObject($nullValue);\n        $this-\u003emyNullDateTime = Cast::nullDateTime($nullValue);\n    }\n}\n````\n\n## Methods\n### static Cast::intval(mixed $value): int\nCast $value to an int.\n\nThrows \\InvalidArgumentException if $value is not one of array, bool, float, int, resource, string, null.\n\n#### static floatval(mixed $value): float\nCast $value to a float.\n\nThrows \\InvalidArgumentException if $value is not one of array, bool, float, int, string, null.\n\n#### static strval(mixed $value): string\nCast $value to a float.\n\nThrows \\InvalidArgumentException if $value is not one of bool, float, int, resource, string, null.\n\n#### static boolval(mixed $value): bool\nCast $value to a float.\n\nThrows \\InvalidArgumentException if $value is not one of array, bool, float, int, string, null.\n\n#### static nullInt(mixed $value): ?int\nCast $value to int|null.\n\nThrows \\InvalidArgumentException if $value is not one of array, bool, float, int, resource, string, null.\n\n#### static nullFloat(mixed $value): ?float\nCast $value to float|null.\n\nThrows \\InvalidArgumentException if $value is not one of array, bool, float, int, string, null.\n\n#### static nullString(mixed $value): ?string\nCast $value to string|null.\n\nThrows \\InvalidArgumentException if $value is not one of bool, float, int, resource, string, null.\n\n#### static nullBool(mixed $value): ?bool\nCast $value to bool|null.\n\nThrows \\InvalidArgumentException if $value is not one of array, bool, float, int, string, null.\n\n#### static nullArray(mixed $value): ?array\nCast $value to array|null.\n\nSee https://www.php.net/manual/en/language.types.array.php#language.types.array.casting\n\n#### static nullObject(mixed $value): ?object\nCast $value to object|null.\n\nSee See https://www.php.net/manual/en/language.types.object.php#language.types.object.casting\n\n#### static nullDateTime(mixed $value): ?DateTime\nCast $value to DateTime|null.\n\nThrows \\InvalidArgumentException if $value is not one of bool, float, int, resource, string, null.\nSee https://www.php.net/manual/en/datetime.construct.php for valid DateTime string formats.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxactsystems%2Fcast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxactsystems%2Fcast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxactsystems%2Fcast/lists"}