{"id":21466555,"url":"https://github.com/permafrost-dev/php-code-search","last_synced_at":"2025-07-14T21:36:26.680Z","repository":{"id":41266449,"uuid":"382847668","full_name":"permafrost-dev/php-code-search","owner":"permafrost-dev","description":"Search PHP source code for function \u0026 method calls, variables, and more from PHP.","archived":false,"fork":false,"pushed_at":"2024-09-03T04:34:58.000Z","size":371,"stargazers_count":27,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-30T10:04:43.672Z","etag":null,"topics":["code-search","package","php","php-library","search"],"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/permafrost-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"permafrost-dev"}},"created_at":"2021-07-04T12:34:10.000Z","updated_at":"2024-09-24T20:34:26.000Z","dependencies_parsed_at":"2024-01-16T14:03:56.297Z","dependency_job_id":"4f28be80-09c8-4564-940a-f4e0ff3317b1","html_url":"https://github.com/permafrost-dev/php-code-search","commit_stats":{"total_commits":222,"total_committers":3,"mean_commits":74.0,"dds":0.2432432432432432,"last_synced_commit":"be515830f1dc4a532283ba489486d8484915232e"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"purl":"pkg:github/permafrost-dev/php-code-search","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permafrost-dev%2Fphp-code-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permafrost-dev%2Fphp-code-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permafrost-dev%2Fphp-code-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permafrost-dev%2Fphp-code-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/permafrost-dev","download_url":"https://codeload.github.com/permafrost-dev/php-code-search/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permafrost-dev%2Fphp-code-search/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265352601,"owners_count":23751925,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["code-search","package","php","php-library","search"],"created_at":"2024-11-23T08:14:36.789Z","updated_at":"2025-07-14T21:36:26.646Z","avatar_url":"https://github.com/permafrost-dev.png","language":"PHP","funding_links":["https://github.com/sponsors/permafrost-dev"],"categories":[],"sub_categories":[],"readme":"# Searching PHP source code made easy\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://static.permafrost.dev/images/php-code-search/php-code-search-logo.png\" alt=\"php-code-search logo\" height=\"200\" style=\"block\"\u003e\n    \u003cbr\u003e\u003cbr\u003e\n    \u003cimg src=\"https://img.shields.io/github/v/release/permafrost-dev/php-code-search.svg?sort=semver\u0026logo=github\u0026\" alt=\"Package Version\"\u003e\n    \u003cimg src=\"https://img.shields.io/packagist/dt/permafrost-dev/php-code-search?logo=packagist\u0026logoColor=%23fff\" alt=\"Downloads\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/permafrost-dev/php-code-search.svg?logo=opensourceinitiative\u0026\" alt=\"license\"\u003e\n    \u003cimg src=\"https://github.com/permafrost-dev/php-code-search/actions/workflows/run-tests.yml/badge.svg?branch=main\" alt=\"Test Run Status\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/permafrost-dev/php-code-search/branch/main/graph/badge.svg\" alt=\"code coverage\"\u003e\n\u003c/p\u003e\n\n---\n\nSearch PHP source code for function \u0026 method calls, variable assignments, classes and more directly from PHP.\n\n---\n\n## Installation\n\n```bash\ncomposer require permafrost-dev/php-code-search\n```\n\n## Searching\n\nTo search a file, use the `search` method.  Its only parameter may be either a string containing a valid filename or an instance of `\\Permafrost\\PhpCodeSearch\\Support\\File`.\n\nTo search a string instead, use the `searchCode` method.\n\nThe search methods return an instance of `Permafrost\\PhpCodeSearch\\Results\\FileSearchResults`, which has a `results` property.  \n\nEach `result` is an instance of `Permafrost\\PhpCodeSearch\\Results\\SearchResult` with the following properties:\n\n- `node` - the specific item that was found\n  - `node-\u003ename(): string`\n- `location` - the location in the file that the item was found\n  - `location-\u003estartLine(): int`\n  - `location-\u003eendLine(): int`\n- `snippet` - a snippet of code lines from the file with the result line in the middle\n  - `snippet-\u003etoString(): string`\n- `file()` _(method)_ - provides access to the file that was searched\n\n### Searching\n\nTo search through the code in a string or file, use the `Searcher` class:\n\n```php\nuse Permafrost\\PhpCodeSearch\\Searcher;\n\n$searcher = new Searcher();\n```\n\nTo search a file, use the `search` method, and the `searchCode` method to search a string of code.\n\n```php\n$searcher\n    -\u003efunctions(['strtolower', 'strtoupper'])\n    -\u003esearch('./file1.php');\n\n$searcher\n    -\u003evariables(['/^one[A-Z]$/'])\n    -\u003esearchCode('\u003c?php $oneA = \"1a\";');\n```\n\nWhen searching using any of the available methods, regular expressions can be used by surrounding the name with slashes `/`, i.e. `/test\\d+/`.\n\n### Variable names\n\nTo search for variables by name, use the `variables` method.\n\n```php\n$results = $searcher\n    -\u003evariables(['twoA', '/^one.$/'])\n    -\u003esearchCode('\u003c?php '.\n    '    $oneA = \"1a\";'.\n    '    $oneB = \"1b\";'.\n    '    $twoA = \"2a\";'.\n    '    $twoB = \"2b\";'.\n    '');\n    \nforeach($results-\u003eresults as $result) {\n    echo \"Found '{$result-\u003enode-\u003ename()}' on line {$result-\u003elocation-\u003estartLine}\" . PHP_EOL;\n}\n```\n\n### Functions\n\nTo search for function calls or definitions, use the `functions` method.  \n\n```php\n// search for references AND definitions for 'strtolower' and/or 'myfunc'\n$searcher\n    -\u003efunctions(['strtolower', 'myfunc'])\n    -\u003esearch('file1.php');\n```\n\n### Method calls\n\nTo search for a method call by name, use the `methods` method.\n\nMethod call nodes have an `args` property that can be looped through to retrieve the arguments for the method call.\n\n```php\n$results = $searcher\n    -\u003emethods(['/test(One|Two)/'])\n    -\u003esearchCode('\u003c?php '.\n      '    $obj-\u003etestOne(\"hello world 1\"); '.\n      '    $obj-\u003etestTwo(\"hello world\", 2); '.\n      ''\n    );\n    \nforeach($results-\u003eresults as $result) {\n    echo \"Found '{$result-\u003enode-\u003ename()}' on line {$result-\u003elocation-\u003estartLine}\" . PHP_EOL;\n\n    foreach($result-\u003enode-\u003eargs as $arg) {\n        echo \"  argument: '{$arg-\u003evalue}'\" . PHP_EOL;\n    }\n}\n```\n\n### Static calls\n\nTo search for static method or property calls, use the `static` method.\n\nValid search terms are either a class name like `Cache`, or a class name and a method name like `Cache::remember`. \n\n```php\n$searcher\n    -\u003estatic(['Ray', 'Cache::has', 'Request::$myProperty'])\n    -\u003esearch('./app/Http/Controllers/MyController.php');\n```\n\n### Classes\n\nTo search for either a class definition or a class created by the `new` keyword, use the `classes` method. \n\n```php\n$searcher\n    -\u003eclasses(['MyController'])\n    -\u003esearch('./app/Http/Controllers/MyController.php');\n```\n\n### Variable assignments\n\nTo search for a variable assignment by variable name, use the `assignments` method. _Note: The `$` should be omitted._\n\n```php\n$searcher\n    -\u003eassignments(['myVar'])\n    -\u003esearch('./app/Http/Controllers/MyController.php');\n```\n\n### Results without code snippets\n\nTo return search results without associated code snippets, use the `withoutSnippets` method:\n\n```php\n$searcher\n    -\u003ewithoutSnippets()\n    -\u003efunctions(['strtolower'])\n    -\u003esearch('file1.php');\n```\n\n\n## Testing\n\n```bash\n./vendor/bin/phpunit\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Patrick Organ](https://github.com/patinthehat)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermafrost-dev%2Fphp-code-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermafrost-dev%2Fphp-code-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermafrost-dev%2Fphp-code-search/lists"}