code-examples-template

为 PHP 文档生成代码示例:创建简洁、可直接复制粘贴的示例,并包含预期输出。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "code-examples-template":https://skillpi.com/zh/skills/deepskill-fb2106b3fbc45143d49ad6969d4b3828e25274b84072d119a71cff0f4bdec1d0。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 PHP 文档生成代码示例:创建简洁、可直接复制粘贴的示例,并包含预期输出。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
输入和输出
减记
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: code-examples-template
description: Generates code examples for PHP documentation. Creates minimal, copy-paste ready examples with expected output.

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

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

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

## Basic Usage

Start with the simplest case:

```php
$client = new Client();
$result = $client->ping();
// "pong"

With Configuration

Add configuration options:

$client = new Client([
    'timeout' => 30,
]);
$result = $client->ping();
// "pong"

With Authentication

Add authentication:

$client = new Client([
    'api_key' => 'your-key',
    'timeout' => 30,
]);
$result = $client->process('data');
// {"status": "success", "id": "..."}

Production Ready

Full example with error handling:

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):

// ✅ 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:

$result = $transformer->slugify($input);

Output:

$result = "hello-world";

### Comparison Pattern

```markdown
### Framework Comparison

**Symfony:**
```php
use Symfony\Component\HttpFoundation\Response;

return new Response('Hello', 200);

Laravel:

return response('Hello', 200);

Native:

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

$client = new Client([
    // highlight-next-line
    'api_key' => 'your-key',  // <-- This is important
    'timeout' => 30,
]);

Showing Line Numbers

```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

$item = $client->items->get('item_abc123');
echo $item->name; // "New Item"

Update

$item = $client->items->update('item_abc123', [
    'price' => 79.99,
]);
echo $item->price; // 79.99

Delete

$client->items->delete('item_abc123');
// No return value, throws on error

List

$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 project

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 Minimal/Complete/Progressive 三种代码示例模板,覆盖不同文档需求
  • 包含 CRUD、错误处理、异步操作等常见模式,实用性强
  • 附带质量清单,帮助生成高质量可运行的代码示例
触发精准95/100

亮点

  • description 明确聚焦 PHP 文档代码示例生成,触发词精准
  • 覆盖多种使用场景和示例类型,边界清晰
结构规范95/100

待提升项

  • 文档长度 原报告严重程度:轻微

    SKILL.md 文件约 400 行,内容较密集

    改进建议:建议适当拆分章节或增加目录导航,提升可读性

亮点

  • 结构清晰,分类型、模板、模式、清单等章节组织
  • 包含大量端到端示例,frontmatter 完整
执行可靠90/100

亮点

  • 静态文档模板,无外部依赖或不可逆操作,执行风险低
  • 内容自包含,用户可直接复制使用
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。