Projekt

Obecné

Profil

Akce

Development

  • pro vývoj využíváme editor Visual Studio Code

Visual Studio Code

  • každý projekt by měl mít svůj vlastní workspace
  • pro vyznačení všech souborů/adresářů patřících do workspace je potřeba do folders připsat všechny cesty
"folders": [
    {
            "path": "." 
    }
]

  • nastavení jednotlivých rozšíření a editoru lze zakomponovat pod klíč settings
"settings": {
    "php.suggest.basic":false,
    "files.autoSave": "afterDelay",
    "php-cs-fixer.onsave": false,
    "php-cs-fixer.rules": "@PSR2",
    "php-cs-fixer.config": ".php_cs",
    "php-cs-fixer.executablePath": "${workspaceRoot}/vendor/bin/php-cs-fixer",
    "php-cs-fixer.executablePathWindows": "${workspaceRoot}\\vendor\\bin\\php-cs-fixer" 
}
  • workspace má pro sebe nastavený seznam doporučených rozšíření
"extensions": {
    "recommendations": [
        "vscode-icons-team.vscode-icons",
        "felixfbecker.php-intellisense",
        "junstyle.php-cs-fixer" 
    ]
}

  • do workspace je přidán i linter, které lze přes F1 spustit pro složku src
"tasks": {
    "version": "2.0.0",
    "tasks": [{
        "label": "PHP Linter",
        "command": "${workspaceRoot}/vendor/bin/php-cs-fixer",
        "args": ["fix", "--dry-run", "--config", ".php_cs", "--stop-on-violation", "--using-cache=no"],
        "windows":{
            "command": "${workspaceRoot}\\vendor\\bin\\php-cs-fixer",
            "args": ["fix", "--dry-run", "--config", ".php_cs", "--stop-on-violation", "--using-cache=no"],
        }
    }]
}
  • pro debug kódu v php, je připraven příkaz v launch, který by měl spolu s nainstalovaný rozšířením a konfigurací php_fpm containeru umožnit debug našeho projektu
  • zatím nefunkční
"launch": {
    "configurations": [{
           "name": "Listen for XDebug",
           "type": "php",
           "request": "launch",
        "port": 9000,
        "pathMappings": {  
            "/var/www/symfony/public": "${workspaceRoot}/public" 
        }}]
}

PHP Linter

  • nainstalované rozšíření do vscode, umožňuje po stisknutí kombinace kláves, naformátovat soubor, podle dané metriky/formátu a konfiguračního souboru .php_cs
?php
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__.'/src')
    ->notPath('Kernel.php')

;

return PhpCsFixer\Config::create()
    ->setRules(array(
        '@Symfony' => true,
        'array_indentation' => true,
        'array_syntax' => array('syntax' => 'short'),
        'combine_consecutive_unsets' => true,
        'method_separation' => true,
        'no_multiline_whitespace_before_semicolons' => true,
        'single_quote' => true,

        'binary_operator_spaces' => array(
            'align_double_arrow' => false,
            'align_equals' => false,
        ),
        'blank_line_before_statement' => array('statements' => array(
            'return',
        )),
        'braces' => array(
            'allow_single_line_closure' => true,
            'position_after_functions_and_oop_constructs' => 'same'
        ),
        'cast_spaces' => true,
        'class_definition' => array('singleLine' => true),
        'concat_space' => array('spacing' => 'none'),
        'hash_to_slash_comment' => true,
        'no_extra_consecutive_blank_lines' => array(
            'curly_brace_block',
            'extra',
            'break',
            'continue',
            'parenthesis_brace_block',
            'return',
            'square_brace_block',
            'throw',
            'use',
        ),
        'no_whitespace_before_comma_in_array' => true,
        'ordered_imports' => array('imports_order' => array(
            'const',
            'class',
            'function'
        ), 'sort_algorithm' => 'length'),
        'short_scalar_cast' => true,
        'simplified_null_return' => true,
        'single_import_per_statement' => true,
        'single_line_after_imports' => true,
        'single_line_comment_style' => true,
        'standardize_increment' => true,
        'standardize_not_equals' => true,
        'space_after_semicolon' => array(
            'remove_in_empty_for_expressions' => true,
        ),
        'switch_case_semicolon_to_colon' => true,
        'switch_case_space' => true,
        'ternary_operator_spaces' => true,
        'ternary_to_null_coalescing' => true,
        'trim_array_spaces' => true,
        'unary_operator_spaces' => true,
        'visibility_required' => true,
        'whitespace_after_comma_in_array' => true,
        'align_multiline_comment' => true,
        'constant_case' => true,
        'declare_equal_normalize' => true,
        'elseif' => true,
        'function_declaration' => true,
        'function_typehint_space' => true,
        'global_namespace_import' => array(
            'import_classes' => true,
            'import_constants' => true,
            'import_functions' => true,
        ),
        'include' => true,
        'linebreak_after_opening_tag' => true,
        'list_syntax' => array('syntax' => 'short'),
        'lowercase_cast' => true,
        'lowercase_keywords' => true,
        'lowercase_static_reference' => true,
        'magic_constant_casing' => true,
        'magic_method_casing' => true,
        'method_argument_space' => array(
            'on_multiline' => 'ensure_fully_multiline',
            'keep_multiple_spaces_after_comma' => false,
        )
    ))
    //->setIndent("\t")
    ->setLineEnding("\n")
    ->setFinder($finder)
;

Docker

  • pro vývoj na dev prostředí, byly zaveden zvlášť Dockerfile pro php-fpm
  • do tohoto Dockerfilu jsou zakomponvány balíčky, kterou jsou určeny výhradně pro vývojové prostředí
  • jejich deploy na produkční server by mohl vytvořit bezpečnostní díry, proto jsou přehledně odděleny

Aktualizováno uživatelem Tomáš Ballák před asi 4 roky(ů) · 13 revizí