All Projects → Setasign → php-stub-generator

Setasign / php-stub-generator

Licence: MIT license
A tool to generate stub-files for your php classes.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-stub-generator

Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+6230.77%)
Mutual labels:  stubs
Sinon
Test spies, stubs and mocks for JavaScript.
Stars: ✭ 8,828 (+33853.85%)
Mutual labels:  stubs
woocommerce-stubs
WooCommerce function and class declaration stubs for static analysis.
Stars: ✭ 49 (+88.46%)
Mutual labels:  stubs
ruby-api-stubs
Auto-generated stubs for the SketchUp Ruby API. Useful for IDE intellisense and auto-complete.
Stars: ✭ 19 (-26.92%)
Mutual labels:  stubs
hanbi
A small javascript library for stubbing and spying on methods/functions.
Stars: ✭ 49 (+88.46%)
Mutual labels:  stubs
laravel-repository-pattern
Files autogenerator for repositorry pattern
Stars: ✭ 46 (+76.92%)
Mutual labels:  stubs
aem-stubs
Tool for providing sample data for AEM applications in a simple and flexible way. Stubbing server on AEM, no separate needed.
Stars: ✭ 40 (+53.85%)
Mutual labels:  stubs
micropy-stubs
Automatically Generated Stub Packages for Micropy-Cli and whomever else
Stars: ✭ 25 (-3.85%)
Mutual labels:  stubs

php-stub-generator

A tool to generate stub-files for your php classes.

The main purpose for this tool is to generate stub-files from php classes to have code completion for your IDE when encrypting your library with e.g. the ioncube encoder.

Minimum PHP Version License

Installation

A basic installation via Composer could be done this way:

composer require setasign/php-stub-generator

Composer will install the tool to your project's vendor/setasign/php-stub-generator directory.

Basic usage

<?php
declare(strict_types=1);

use setasign\PhpStubGenerator\PhpStubGenerator;
use setasign\PhpStubGenerator\Reader\AllFiles;

require_once __DIR__ . '/vendor/autoload.php';

$generator = new PhpStubGenerator();
$generator->addSource(
    'setapdf-core',
    new AllFiles(__DIR__ . '/vendor/setasign/setapdf-core/library')
);
$output = $generator->generate();

file_put_contents(__DIR__ . '/setapdf-core-stub.php', $output);

Alternatively you could just call the cli helper.

vendor/bin/php-stub-generator generate setapdf-core/library setapdf-core-stub.php

Settings

The PhpStubGenerator class has following settings:

class PhpStubGenerator
{
    /**
     * End of line character(s).
     *
     * Doesn't change the used EOL character(s) of doc blocks.
     *
     * @var string
     */
    public static $eol = "\n";

    /**
     * Tab character(s)
     *
     * @var string
     */
    public static $tab = '    ';

    /**
     * If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1)
     * 
     * Within the cli tool can be set with the option "--addClassConstantsVisibility"
     * 
     * @var bool
     */
    public static $addClassConstantsVisibility = false;
}

Drawbacks / TODOs

  • Traits are not supported yet and probably won't be because of bugs like this. The actual reflection api doesn't give enough information to rebuild the conflict resolution block. Additionally the "declaring class" of imported trait methods is the importing class and not like expected the trait.
  • Calculated constants or constants that use other constants like __DIR__ will be filled with the values of the runtime environment.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].