Skip to content

Instantly share code, notes, and snippets.

@vikbert
Last active December 11, 2018 14:31
Show Gist options
  • Select an option

  • Save vikbert/6ad48772d581969d50b2b6e0b7a3dfc8 to your computer and use it in GitHub Desktop.

Select an option

Save vikbert/6ad48772d581969d50b2b6e0b7a3dfc8 to your computer and use it in GitHub Desktop.
[composer] best practice for using composer #composer

Koza composer

execute on Mac Host machine $ env COMPOSER_MEMORY_LIMIT=-1 composer update --no-scripts

# update feature branch packages
$ composer update vendor/{package name}

# avoid the problem with out of memory in KOZA
$ COMPOSER_MEMORY_LIMIT=-1 composer install vendor/lib

# ausserhalb VM ausfuehren
$ env COMPOSER_MEMORY_LIMIT=-1 composer install vendor/lib --ignore-platform-reqs --no-scripts

can not find function usage

$ env COMPOSER_MEMORY_LIMIT=-1 composer install vendor/lib --ignore-platform-reqs --no-scripts
// in phpstorm: invalid cache/restart

composer install specific package

composer require webmozart/assert --no-scripts --ignore-platform-reqs

composer commands

composer req --dev phpunit/phpunit
composer req --dev behat/behat
composer req --dev phpstan/phpstan
composer req --dev friendsofphp/php-cs-fixer

Tools Usage

# phpstan
vendor/bin/phpstan analyse src tests

# phpunit
vendor/bin/phpunit tests

# php-cs-fixer
vendor/bin/php-cs-fixer fix

Mini Project with Composer

1. step: create composer.json

{
    "autoload": {
        "psr-4": {
            "MayApp\\": "src/MyApp"
        },
        "classmap": [
            "src/MyApp"
        ]
    },
    "require-dev": {
        "phpunit/phpunit": "^7.3",
        "friendsofphp/php-cs-fixer": "^2.12"
    },
    "scripts": {
        "test": "vendor/bin/phpunit tests/",
        "fix": "vendor/bin/php-cs-fixer fix"
    }
}

2. step: create .php_cs

<?php

$finder = PhpCsFixer\Finder::create()
    ->exclude([
        'vendor',
    ])
    ->in(__DIR__)
;

return PhpCsFixer\Config::create()
    ->setRules([
        '@Symfony' => true,
        'yoda_style' => [
            'equal' => null,
            'identical' => null,
            'less_and_greater' => null,
        ],
        'concat_space' => ['spacing' => 'one'],
        'declare_equal_normalize' => ['space' => 'single'],
        'array_syntax' => ['syntax' => 'short'],
        'phpdoc_align' => [
            'align' => 'left',
            'tags' => ['param', 'property', 'return', 'throws', 'type', 'var', 'method']
        ],
        'phpdoc_to_comment' => false,
        'no_superfluous_phpdoc_tags' => true,
    ])
    ->setFinder($finder)
;

3. step: create all folders

mkdir -p src/MyApp tests

4. step: composer install and start

composer test
composer fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment