acc-code-examples-template
Generates code examples for PHP documentation. Creates minimal, copy-paste ready examples with expected output.
Best use case
acc-code-examples-template is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Generates code examples for PHP documentation. Creates minimal, copy-paste ready examples with expected output.
Teams using acc-code-examples-template should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/acc-code-examples-template/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How acc-code-examples-template Compares
| Feature / Agent | acc-code-examples-template | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Generates code examples for PHP documentation. Creates minimal, copy-paste ready examples with expected output.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# Code Examples Template Generator
Generate effective code examples for documentation.
## Example Principles
### The Three Types
| Type | Purpose | Length | Use When |
|------|---------|--------|----------|
| **Minimal** | Show single concept | 5-10 lines | Teaching one thing |
| **Complete** | Show full usage | 20-50 lines | Production reference |
| **Progressive** | Build complexity | 3+ examples | Tutorial style |
## Example Templates
### Minimal Example
```php
<?php
use Vendor\Package\Client;
$client = new Client();
$result = $client->process('data');
echo $result->status; // "success"
```
**Characteristics:**
- Single concept
- No error handling
- Shows expected output
- Copy-paste ready
### Complete Example
```php
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Vendor\Package\Client;
use Vendor\Package\Config;
use Vendor\Package\Exception\ClientException;
// Configuration
$config = new Config(
apiKey: getenv('API_KEY') ?: throw new RuntimeException('API_KEY required'),
timeout: 30,
retries: 3,
);
// Initialize client
$client = new Client($config);
try {
// Make request
$result = $client->process([
'data' => 'input value',
'options' => ['validate' => true],
]);
// Handle success
echo "Status: {$result->status}\n";
echo "ID: {$result->id}\n";
} catch (ClientException $e) {
// Handle error
echo "Error: {$e->getMessage()}\n";
exit(1);
}
/* Output:
Status: success
ID: res_abc123
*/
```
**Characteristics:**
- Full imports
- Error handling
- Configuration
- Comments for sections
- Expected output
### Progressive Example
```markdown
## Basic Usage
Start with the simplest case:
```php
$client = new Client();
$result = $client->ping();
// "pong"
```
## With Configuration
Add configuration options:
```php
$client = new Client([
'timeout' => 30,
]);
$result = $client->ping();
// "pong"
```
## With Authentication
Add authentication:
```php
$client = new Client([
'api_key' => 'your-key',
'timeout' => 30,
]);
$result = $client->process('data');
// {"status": "success", "id": "..."}
```
## Production Ready
Full example with error handling:
```php
try {
$client = new Client([
'api_key' => getenv('API_KEY'),
'timeout' => 30,
'retries' => 3,
]);
$result = $client->process('data');
echo $result->status;
} catch (ClientException $e) {
error_log($e->getMessage());
exit(1);
}
```
```
## Example Patterns
### Before/After Pattern
```markdown
### Refactoring Example
**Before (Anti-pattern):**
```php
// ❌ Don't do this
$data = file_get_contents('data.json');
$json = json_decode($data);
if ($json === null) {
die('Invalid JSON');
}
```
**After (Recommended):**
```php
// ✅ Do this instead
use Vendor\Package\JsonLoader;
$loader = new JsonLoader();
$data = $loader->load('data.json');
// Throws JsonException on invalid data
```
```
### Input/Output Pattern
```markdown
### String Transformation
**Input:**
```php
$input = "Hello World";
```
**Code:**
```php
$result = $transformer->slugify($input);
```
**Output:**
```php
$result = "hello-world";
```
```
### Comparison Pattern
```markdown
### Framework Comparison
**Symfony:**
```php
use Symfony\Component\HttpFoundation\Response;
return new Response('Hello', 200);
```
**Laravel:**
```php
return response('Hello', 200);
```
**Native:**
```php
http_response_code(200);
echo 'Hello';
```
```
## Code Block Guidelines
### Language Tags
```markdown
```php # PHP code
```bash # Shell commands
```json # JSON data
```yaml # YAML config
```sql # Database queries
```diff # Code changes
```
### Highlighting Important Parts
```php
<?php
$client = new Client([
// highlight-next-line
'api_key' => 'your-key', // <-- This is important
'timeout' => 30,
]);
```
### Showing Line Numbers
```markdown
```php {1,3-5}
<?php // Line 1
// Line 2
$config = new Config(); // Line 3
$config->setTimeout(30); // Line 4
$config->setRetries(3); // Line 5
```
```
## Common Patterns
### CRUD Operations
```markdown
### Create
```php
$item = $client->items->create([
'name' => 'New Item',
'price' => 99.99,
]);
echo $item->id; // "item_abc123"
```
### Read
```php
$item = $client->items->get('item_abc123');
echo $item->name; // "New Item"
```
### Update
```php
$item = $client->items->update('item_abc123', [
'price' => 79.99,
]);
echo $item->price; // 79.99
```
### Delete
```php
$client->items->delete('item_abc123');
// No return value, throws on error
```
### List
```php
$items = $client->items->list(['limit' => 10]);
foreach ($items as $item) {
echo "{$item->name}: {$item->price}\n";
}
```
```
### Error Handling
```markdown
### Handling Errors
```php
use Vendor\Package\Exception\{
NotFoundException,
ValidationException,
RateLimitException,
};
try {
$result = $client->process($data);
} catch (NotFoundException $e) {
// Resource doesn't exist
echo "Not found: {$e->getMessage()}";
} catch (ValidationException $e) {
// Invalid input
foreach ($e->getErrors() as $field => $messages) {
echo "{$field}: " . implode(', ', $messages) . "\n";
}
} catch (RateLimitException $e) {
// Too many requests
sleep($e->getRetryAfter());
// Retry...
}
```
```
### Async Operations
```markdown
### Async Processing
```php
// Start async job
$job = $client->jobs->create([
'type' => 'export',
'params' => ['format' => 'csv'],
]);
echo "Job started: {$job->id}\n";
// Poll for completion
while ($job->status !== 'completed') {
sleep(5);
$job = $client->jobs->get($job->id);
echo "Status: {$job->status}\n";
}
// Get result
$result = $client->jobs->getResult($job->id);
file_put_contents('export.csv', $result->content);
```
```
## Quality Checklist
### Every Example Should
- [ ] Run without modification (except config)
- [ ] Show expected output
- [ ] Use realistic data (not foo/bar)
- [ ] Include necessary imports
- [ ] Follow PSR-12 style
- [ ] Match current API version
### Avoid
- [ ] Abstract examples that don't run
- [ ] Missing `<?php` tag when standalone
- [ ] Outdated syntax or deprecated methods
- [ ] Foo/Bar/Baz placeholder names
- [ ] Missing required configuration
- [ ] Unexplained magic values
## Generation Instructions
When generating code examples:
1. **Choose example type** based on purpose
2. **Use realistic data** (emails, names, prices)
3. **Include expected output** in comments
4. **Show imports** when needed
5. **Add error handling** in complete examples
6. **Test examples** actually run
7. **Match coding style** of the projectRelated Skills
add-template
Add new UI style template to the ui-style-react project. This skill should be used when users want to add a new style template with HTML/CSS code, create a new preview page, or register a template in the system. Triggers include "add template", "create new style", "add new template", or when users provide HTML code for a new UI style.
add-skill-templates
Add new Agent Skill templates to the meta-agent-skills framework.
add-agent-templates
Add new Agent templates to the meta-agent-skills framework.
acc-troubleshooting-template
Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.
acc-readme-template
Generates README.md files for PHP projects. Creates structured documentation with badges, installation, usage, and examples.
acc-mermaid-template
Generates Mermaid diagrams for technical documentation. Provides templates for flowcharts, sequence diagrams, class diagrams, ER diagrams, and C4 models.
acc-getting-started-template
Generates Getting Started guides for PHP projects. Creates step-by-step tutorials for first-time users.
acc-changelog-template
Generates CHANGELOG.md files following Keep a Changelog format. Creates version history documentation.
acc-architecture-doc-template
Generates ARCHITECTURE.md files for PHP projects. Creates layer documentation, component descriptions, and architectural diagrams.
acc-api-doc-template
Generates API documentation for PHP projects. Creates endpoint documentation with parameters, responses, and examples.
acc-adr-template
Generates Architecture Decision Records (ADR) for PHP projects. Creates structured decision documentation with context, decision, and consequences.
ac-to-examples
将抽象的Acceptance Criteria(Given-When-Then)转换为具体的数值示例和真实对话,让AC对PM/客户/测试人员更易懂。适合在AC编写完成后、准备测试或向客户展示时使用,当AC格式正确但过于抽象时。帮助不熟悉BDD的PM/BA/测试人员理解测试场景,让AC从抽象规则变成可直接用于手动测试的具体步骤。