symfony / maker-bundle

Symfony Maker Bundle
https://symfony.com/
MIT License
3.36k stars 406 forks source link

make:user fails with error "The indentation must be greater than zero." #1278

Closed 4d4ch4u32 closed 6 months ago

4d4ch4u32 commented 1 year ago

Symfony version(s) affected

6.2.5

Description

php bin/console make:user fails with error The indentation must be greater than zero..

I'm using Symfony in combination with api-platform and doctrine. All yaml files are validated successfully.

How to reproduce

Command with values I used:

[backend]::/srv/api # php bin/console make:user -vvv

 The name of the security user class (e.g. User) [User]:
 > User

 Do you want to store user data in the database (via Doctrine)? (yes/no) [yes]:
 > yes

 Enter a property name that will be the unique "display" name for the user (e.g. email, username, uuid) [email]:
 > email

 Will this app need to hash/check user passwords? Choose No if passwords are not needed or will be checked/hashed by some other system (e.g. a single sign-on server).

 Does this app need to hash/check user passwords? (yes/no) [yes]:
 > yes

 created: src/Entity/User.php
 created: src/Repository/UserRepository.php

In Dumper.php line 33:

  [InvalidArgumentException]
  The indentation must be greater than zero.

Exception trace:
  at /srv/api/vendor/symfony/yaml/Dumper.php:33
 Symfony\Component\Yaml\Dumper->__construct() at /srv/api/vendor/symfony/yaml/Yaml.php:92
 Symfony\Component\Yaml\Yaml::dump() at /srv/api/vendor/symfony/maker-bundle/src/Util/YamlSourceManipulator.php:718
 Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator->convertToYaml() at /srv/api/vendor/symfony/maker-bundle/src/Util/YamlSourceManipulator.php:338
 Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator->addNewKeyToYaml() at /srv/api/vendor/symfony/maker-bundle/src/Util/YamlSourceManipulator.php:186
 Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator->updateData() at /srv/api/vendor/symfony/maker-bundle/src/Util/YamlSourceManipulator.php:205
 Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator->updateData() at /srv/api/vendor/symfony/maker-bundle/src/Util/YamlSourceManipulator.php:86
 Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator->setData() at /srv/api/vendor/symfony/maker-bundle/src/Security/SecurityConfigUpdater.php:194
 Symfony\Bundle\MakerBundle\Security\SecurityConfigUpdater->updatePasswordHashers() at /srv/api/vendor/symfony/maker-bundle/src/Security/SecurityConfigUpdater.php:49
 Symfony\Bundle\MakerBundle\Security\SecurityConfigUpdater->updateForUserClass() at /srv/api/vendor/symfony/maker-bundle/src/Maker/MakeUser.php:191
 Symfony\Bundle\MakerBundle\Maker\MakeUser->generate() at /srv/api/vendor/symfony/maker-bundle/src/Command/MakerCommand.php:93
 Symfony\Bundle\MakerBundle\Command\MakerCommand->execute() at /srv/api/vendor/symfony/console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /srv/api/vendor/symfony/console/Application.php:1040
 Symfony\Component\Console\Application->doRunCommand() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:88
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/api/vendor/symfony/console/Application.php:314
 Symfony\Component\Console\Application->doRun() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/api/vendor/symfony/console/Application.php:168
 Symfony\Component\Console\Application->run() at /srv/api/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /srv/api/vendor/autoload_runtime.php:29
 require_once() at /srv/api/bin/console:11

make:user [--is-entity] [--identity-property-name IDENTITY-PROPERTY-NAME] [--with-password] [--] [<name>]

Possible Solution

No response

Additional Context

[backend]::/srv/api # composer show | grep symfony
escapestudios/symfony2-coding-standard         3.13.0           CodeSniffer ruleset for the Symfony 2+ coding standard
phpstan/phpstan-symfony                        1.2.20           Symfony Framework extensions and rules for PHPStan
symfony/asset                                  v6.2.5           Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/browser-kit                            v6.2.5           Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms pro...
symfony/cache                                  v6.2.5           Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts                        v3.2.0           Generic abstractions related to caching
symfony/config                                 v6.2.5           Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                                v6.2.5           Eases the creation of beautiful and testable command line interfaces
symfony/dependency-injection                   v6.2.5           Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts                  v3.2.0           A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge                        v6.2.5           Provides integration for Doctrine with various Symfony components
symfony/dom-crawler                            v6.2.5           Eases DOM navigation for HTML and XML documents
symfony/dotenv                                 v6.2.5           Registers environment variables from a .env file
symfony/error-handler                          v6.2.5           Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher                       v6.2.5           Provides tools that allow your application components to communicate with each other by dispatching events ...
symfony/event-dispatcher-contracts             v3.2.0           Generic abstractions related to dispatching event
symfony/filesystem                             v6.2.5           Provides basic utilities for the filesystem
symfony/finder                                 v6.2.5           Finds files and directories via an intuitive fluent interface
symfony/flex                                   v1.19.4          Composer plugin for Symfony
symfony/framework-bundle                       v6.2.5           Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client                            v6.2.5           Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts                  v3.2.0           Generic abstractions related to HTTP clients
symfony/http-foundation                        v6.2.5           Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                            v6.2.5           Provides a structured process for converting a Request into a Response
symfony/intl                                   v6.2.5           Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library
symfony/maker-bundle                           v1.48.0          Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget ...
symfony/monolog-bridge                         v6.2.5           Provides integration for Monolog with various Symfony components
symfony/monolog-bundle                         v3.8.0           Symfony MonologBundle
symfony/password-hasher                        v6.2.5           Provides password hashing utilities
symfony/phpunit-bridge                         v6.2.5           Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-intl-grapheme                 v1.27.0          Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-normalizer               v1.27.0          Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                      v1.27.0          Symfony polyfill for the Mbstring extension
symfony/polyfill-php56                         v1.20.0          Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php80                         v1.27.0          Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-uuid                          v1.27.0          Symfony polyfill for uuid functions
symfony/property-access                        v6.2.5           Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                          v6.2.5           Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge                   v6.2.5           Provides integration for ProxyManager with various Symfony components
symfony/routing                                v6.2.5           Maps an HTTP request to a set of configuration variables
symfony/runtime                                v6.2.5           Enables decoupling PHP applications from global state
symfony/security-bundle                        v6.2.5           Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core                          v6.2.5           Symfony Security Component - Core Library
symfony/security-csrf                          v6.2.5           Symfony Security Component - CSRF Library
symfony/security-http                          v6.2.5           Symfony Security Component - HTTP Integration
symfony/serializer                             v6.2.5           Handles serializing and deserializing data structures, including object graphs, into array structures or ot...
symfony/service-contracts                      v3.2.0           Generic abstractions related to writing services
symfony/stopwatch                              v6.2.5           Provides a way to profile code
symfony/string                                 v6.2.5           Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in...
symfony/translation-contracts                  v3.2.0           Generic abstractions related to translation
symfony/twig-bridge                            v6.2.5           Provides integration for Twig with various Symfony components
symfony/twig-bundle                            v6.2.5           Provides a tight integration of Twig into the Symfony full-stack framework
symfony/uid                                    v6.2.5           Provides an object-oriented API to generate and represent UIDs
symfony/var-dumper                             v6.2.5           Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter                           v6.2.5           Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link                               v6.2.5           Manages links between resources
symfony/web-profiler-bundle                    v6.2.5           Provides a development tool that gives detailed information about the execution of any request
symfony/yaml                                   v6.2.5           Loads and dumps YAML files
weaverryan commented 1 year ago

Hi!

Can you post what your security.yaml looks like at the time of running the command? It may be part of the cause (the error is about trying to update that file)

Cheers!

4d4ch4u32 commented 1 year ago

This is the content of the security.yaml:

security:
#  role_hierarchy:
#    ROLE_ADMIN: [ROLE_USER]
#
#  enable_authenticator_manager: true
#  # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
#  password_hashers:
#    Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
#    App\Entity\User:
#      algorithm: auto
#
#  # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
#  providers:
#    # used to reload user from session & other features (e.g. switch_user)
#    app_user_provider:
#      id: App\Security\UserProvider

  firewalls:
    dev:
      pattern: ^/(_(profiler|wdt)|css|images|js)/
      security: false
#    api:
#      pattern: ^/api/
#      stateless: true
#      provider: app_user_provider
#      jwt: ~
#    main:
#      stateless: true
#      provider: app_user_provider
#      json_login:
#        check_path: /authentication_token
#        username_path: email
#        password_path: password
#        success_handler: lexik_jwt_authentication.handler.authentication_success
#        failure_handler: lexik_jwt_authentication.handler.authentication_failure

      # activate different ways to authenticate
      # https://symfony.com/doc/current/security.html#the-firewall

      # https://symfony.com/doc/current/security/impersonating_user.html
      # switch_user: true

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
  access_control:
    - { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI
    - { path: ^/authentication_token, roles: PUBLIC_ACCESS }
    #- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }

when@test:
  security:
    password_hashers:
      # By default, password hashers are resource intensive and take time. This is
      # important to generate secure password hashes. In tests however, secure hashes
      # are not important, waste resources and increase test times. The following
      # reduces the work factor to the lowest possible values.
      Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
        algorithm: auto
        cost: 4 # Lowest possible value for bcrypt
        time_cost: 3 # Lowest possible value for argon
        memory_cost: 10 # Lowest possible value for argon
weaverryan commented 1 year ago

thanks! I'm wondering if some of those comments are confusing the system.

If you have some time, you could try to create a reproducer test case for YamlSourceManipulator. It's quite easy: create a new file - like this one - https://github.com/symfony/maker-bundle/blob/main/tests/Util/yaml_fixtures/add_array_to_null.test - the 3 sections represent the "starting YAML", the "changes we make to the data", then the final YAML expected. If you create a file in that directory, the YamlSourceManipulatorTest will automatically run it.

Cheers!

jrushlow commented 7 months ago

Source Yaml:

security:
  firewalls:
    dev:
      security: false
#    main:           <------------ Comment is the cause

  access_control:
    - path