Symfony's vendors causing autoloader psr-4 warnings when running composer - symfony

For years, I have been getting these warning whenever I run composer install:
Generating optimized autoload files (authoritative) Class
Sensio\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\AddParamConverterPassTest
located in
./vendor/sensio/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddParamConverterPassTest.php
does not comply with psr-4 autoloading standard. Skipping. Class
Sensio\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\AddExpressionLanguageProvidersPassTest
located in
./vendor/sensio/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddExpressionLanguageProvidersPassTest.php
does not comply with psr-4 autoloading standard. Skipping. Class
Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter\ArgumentNameConverterTest
located in
./vendor/sensio/framework-extra-bundle/Tests/Request/ArgumentNameConverterTest.php
does not comply with psr-4 autoloading standard. Skipping. Class
Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection\DoctrineCommandTest
located in
./vendor/doctrine/doctrine-migrations-bundle/Tests/Command/DoctrineCommandTest.php
does not comply with psr-4 autoloading standard. Skipping.
How could I get rid of these vendor caused warnings?
My composer.json:
{
"name": "...",
"description": "...",
"license": "MIT",
"type": "project",
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
"Features\\": "features/"
},
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
},
"require": {
"php": "^7.2",
"aws/aws-sdk-php": "3.178.*",
"bentools/webpush-bundle": "0.6.*",
"doctrine/doctrine-bundle": "1.12.*",
"doctrine/doctrine-migrations-bundle": "1.3.*",
"doctrine/orm": "2.6.*",
"endroid/qr-code-bundle": "3.4.*",
"friendsofsymfony/jsrouting-bundle": "2.4.*",
"google/apiclient": "2.12.*",
"google/recaptcha": "1.2.*",
"incenteev/composer-parameter-handler": "2.1.*",
"knplabs/knp-time-bundle": "1.15.*",
"sensio/framework-extra-bundle": "5.2.*",
"sonata-project/admin-bundle": "3.76.0",
"sonata-project/core-bundle": "3.20.0",
"sonata-project/doctrine-orm-admin-bundle": "3.24.*",
"stripe/stripe-php": "7.102.*",
"symfony/asset": "4.4.*",
"symfony/monolog-bundle": "3.4.*",
"symfony/orm-pack": "2.2.*",
"symfony/polyfill-apcu": "1.12.*",
"symfony/swiftmailer-bundle": "3.1.*",
"symfony/symfony": "4.4.*",
"symfony/twig-bundle": "4.4.*",
"symfony/webpack-encore-bundle": "1.14.*",
"twig/cssinliner-extra": "3.3.*",
"twig/twig": "2.14.*",
"ua-parser/uap-php": "3.9.*"
},
"require-dev": {
"behat/behat": "3.7.*",
"behat/mink": "1.8.*",
"behat/mink-browserkit-driver": "1.3.*",
"behat/mink-extension": "2.3.*",
"behat/mink-goutte-driver": "1.2.1",
"behat/mink-selenium2-driver": "1.2.0",
"behat/symfony2-extension": "2.1.*",
"phpunit/phpunit": "8.5.*",
"symfony/browser-kit": "4.4.*",
"symfony/phpunit-bridge": "6.0.*",
"symfony/test-pack": "1.0.*"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"platform": {
"php": "7.2.32"
},
"sort-packages": true
},
"extra": {
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "3.4-dev"
}
}
}

If the code is not under your control (vendor code), then you cannot really fix the issue. Either:
you upgrade your dependencies (which could be difficult and problematic, depending on your project, but ultimately the best way forward)
you downgrade Composer to a version that does not raise that warning. That wouldn't be a recommended course of action. You'd lose in performance at the very least, and miss out on bugfixes of later versions.
you ignore the warnings, since warnings are not errors, doubly so on warnings that are shown during installation and not during application rutime.

Related

Symfony 3.1 composer conflicts

I'm resuscitating the old Symfony project.
Cannot "composer install". I have tried to make changes in packages removing composer.lock , changing versions of packages. Bugs are multiplying.
Is there a way to resolve this conflict ?
Problem 1
- symfony/debug is locked to version dev-master and an update of this package was not requested.
- Only one of these can be installed: symfony/symfony[v3.1.0], symfony/debug[dev-master]. symfony/symfony replaces symfony/debug and thus cannot coexist with it.
- symfony/symfony is locked to version v3.1.0 and an update of this package was not requested.
composer.json :
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": { "": "src/" },
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"autoload-dev": {
"psr-4": { "Tests\\": "tests/" }
},
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.1",
"twig/extensions": "^1.4",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"doctrine/doctrine-migrations-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3",
"symfony/monolog-bundle": "^2.8",
"symfony/polyfill-apcu": "^1.0",
"symfony/debug": "3.2.x-dev",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"liuggio/excelbundle": "^2.1",
"stof/doctrine-extensions-bundle": "1.2.*#dev",
"friendsofsymfony/user-bundle": "^2.0",
"friendsofsymfony/jsrouting-bundle": "^2.0",
"jms/serializer-bundle": "^1.1",
"yethee/enum-bundle": "^2.0",
"webit/eval-math": "^1.0",
"yavin/symfony-form-tree": "^1.0",
"knplabs/knp-snappy-bundle": "^1.4",
"friendsofsymfony/rest-bundle": "^2.1"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"bin-dir": "bin",
"platform": {
"php": "5.5.9"
}
},
"minimum-stability": "dev",
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "3.2-dev"
}
}
}
I have no idea how this package version got there.
I was trying to pick the closest version number from packagist before
I have chosen the simplest approach to the problem this time :).
I have been downgrading it number by number to 3.1.0 when it finally ran.

Deploying Symfony on Heroku

I'm trying to deploy a Symfony 5.2 on Heroku, I've already configured the Procfile and the required Config Vars such APP_ENV (prod), APP_SECRET and others related to the project.
Procfile:
web: vendor/bin/heroku-php-apache2 public/
composer.json:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"knplabs/knp-paginator-bundle": "^5.2",
"lexik/jwt-authentication-bundle": "^2.8",
"nelmio/cors-bundle": "^2.0",
"sensio/framework-extra-bundle": "^5.5",
"symfony/asset": "5.1.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/orm-pack": "^1.0",
"symfony/security-bundle": "5.1.*",
"symfony/serializer": "5.1.*",
"symfony/yaml": "5.1.*",
"twig/twig": "^3.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3",
"symfony/maker-bundle": "^1.19",
"symfony/profiler-pack": "^1.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
],
"compile": [
"php bin/console doctrine:migrations:migrate"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.1.*"
}
}
}
No matter what I do I always end up with an error related to something missing such as:
PHP Fatal error: Uncaught Error: Class 'Symfony\Bundle\TwigBundle\TwigBundle' not found in /tmp/build_271a300c_/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:74
My guess is the problem is related with everything ending up in this /tmp/build_271a300c_ folder and when the project is deployed it lost the refereed folder. But I have no idea what to do with this information I appreciate any help.
Solved the problem with, what I think, is nothing more than a workaround.
The deploy process was complaining always about the require-dev dependencies, so I did:
Moved all require-dev to require;
Run composer update to refresh the composer.lock file;
Pushed and tried the deploy again with success.
This solution was take for many people in other issues I read, I'm just describing step-by-step what was done to fix it. Still, I don't think it's the correct fix for this, after all the dev-dependencies shouldn't being installed on prod environment.

Upgrade SF from 2.8 to 3.x.x

I have a problem with the migration from Symfony 2.8 to Symfony 3 and higher. I’ve been trying to update my project for a few days, but I’m blocking the same mistakes. I tried all the solutions I could find on google but no evolutions. Here is my file composer.json
{
"name": "My/project",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"require": {
"php": ">=5.3.9",
"symfony/symfony": "3.0.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"sonata-project/admin-bundle": "3.13",
"sonata-project/doctrine-orm-admin-bundle": "^3.1",
"friendsofsymfony/user-bundle": "^1.3",
"sonata-project/core-bundle": "^3.1",
"sonata-project/easy-extends-bundle": "^2.1",
"sonata-project/user-bundle": "^3.2",
"sonata-project/formatter-bundle": "^3.1",
"knplabs/knp-paginator-bundle": "^2.5",
"sonata-project/intl-bundle": "^2.3",
"google/recaptcha": "^1.1",
"twig/twig": "1.28.2",
"friendsofsymfony/jsrouting-bundle": "^1.6",
"helios-ag/fm-elfinder-bundle": "^6.2",
"vich/uploader-bundle": "1.5.3",
"beberlei/doctrineextensions": "^1.0",
"simplethings/entity-audit-bundle": "^1.0",
"sentry/sentry-symfony": "^1.0",
"rollbar/rollbar": "~1.1",
"mikey179/vfsstream": "^1.6"
},
"require-dev": {
"sensio/generator-bundle": "~3.0",
"doctrine/doctrine-fixtures-bundle": "^2.3",
"hautelook/alice-bundle": "^2.0#beta",
"nelmio/alice": "^3.0#beta",
"theofidry/alice-data-fixtures": "^1.0#beta",
"symfony/phpunit-bridge": "^4.2",
"phpunit/phpunit": "^6.1",
"behat/behat": "^3.4",
"behat/mink": "^1.7",
"behat/mink-selenium2-driver": "^1.3",
"behat/symfony2-extension": "^2.1",
"behat/mink-extension": "^2.2",
"behat/mink-browserkit-driver": "^1.3",
"behat/mink-goutte-driver": "^1.2",
"emuse/behat-html-formatter": "^0.1.0",
"phing/phing": "2.*"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"component-dir": "web/assets"
},
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
}
}
I use this command to update : $ composer update symfony/symfony --with-dependencies --no-scripts
update is not done because apparently I have conflicts with different versions of my dependencies..yet I can’t update my dependencies in a more recent version
Need your help please..
You have a conflict because you cannot have symfony/symfony 3.0.* and symfony/cache 3.4 at the same time.
In fact, other bundles that you have locked at a version are not compatible with symfony 3.0, so you need to bump them up as well.
The minimum viable would be to use these dependencies :
"symfony/symfony": "3.2.*",
"friendsofsymfony/user-bundle": "^2.0",
"sonata-project/user-bundle": "^4.0",
Then just run composer install instead of composer update symfony/symfony. Composer will do its job, and then you'll have to adapt your code to mitigate all the BC breaks, etc ...
If you cannot change your other dependencies, then you're stuck with Sf 2.8.

Imports are highlighted like the packages do not exist (Symfony 4)

I'm working on a Symfony 4 project with PhpStorm 2018.1
It has become common for me to see the use declarations highlighted as if they haven't been installed with composer.
The class belongs to a package which is not directly required in your
composer.json. Please add the package into your composer.json.
The following are installed and show in my composer.json file:
stof/doctrine-extensions-bundle
symfony/orm-pack
Am I missing something here or is this a PhpStorm issue?
composer.json
{
"type": "project",
"license": "proprietary",
"platform": {
"php": "7.1"
},
"require": {
"php": "^7.1",
"ext-iconv": "*",
"sensio/framework-extra-bundle": "^5.1",
"stof/doctrine-extensions-bundle": "^1.3",
"symfony/asset": "^4.1",
"symfony/console": "^4.1",
"symfony/expression-language": "^4.1",
"symfony/flex": "^1.0",
"symfony/form": "^4.1",
"symfony/framework-bundle": "^4.1",
"symfony/lts": "^4#dev",
"symfony/maker-bundle": "^1.5",
"symfony/monolog-bundle": "^3.3",
"symfony/orm-pack": "^1.0",
"symfony/process": "^4.1",
"symfony/profiler-pack": "^1.0",
"symfony/security-bundle": "^4.1",
"symfony/security-guard": "^4.1",
"symfony/serializer-pack": "*",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/twig-bundle": "^4.1",
"symfony/validator": "^4.1",
"symfony/var-dumper": "^4.1",
"symfony/web-link": "^4.1",
"symfony/webpack-encore-pack": "^1.0",
"symfony/yaml": "^4.1"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/debug-pack": "*",
"symfony/dotenv": "^4.1",
"symfony/test-pack": "^1.0",
"symfony/web-server-bundle": "^4.1"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": true
}
}
}
What this message is telling you is that the highlighted classes are only available because the packages containing them have been installed as dependencies of some other packages you require (in this case it's probably because of the symfony/orm-pack package). Generally, relying on such transitive dependencies is not something I would do. Though for the Symfony pack that's something acceptable IMO.
If you are still concerned about this message, you can get rid of it by unpacking symfony/orm-pack (see also http://fabien.potencier.org/symfony4-unpack-the-packs.html):
$ composer unpack symfony/orm-pack
Your import path is correct, your composer.json looks good also.
Try to delete the vendor directory then try to launch composer install.
Try to install Symfony Plugin in your PHPStorm.
EDIT
Do you have the line below in your config/bundles.php ?
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],

Upgrading Doctrine in a Symfony 2.8 application

I need to update to Doctrine 2.5 for a bundle which requires it (Vich\UploaderBundle). However I am facing two difficulties:
How do I know which Doctrine version is compatible with my Symfony 2.8 setup
How do I actually run the upgrade
Composer management is still quite obscure to me, especially the output you get when you try to update.
Here is my current composer.json:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": { "": "src/" },
"files": ["app/AppKernel.php"]
},
"require": {
"php": ">=7.0",
"symfony/symfony": "2.8.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"doctrine/migrations": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master",
"doctrine/doctrine-fixtures-bundle": "dev-master"
"incenteev/composer-parameter-handler": "~2.0",
"apy/datagrid-bundle": "dev-master",
"pagerfanta/pagerfanta": "dev-master",
"white-october/pagerfanta-bundle": "dev-master",
"idci/admin-generator-bundle": "dev-master",
"mopa/bootstrap-bundle": "dev-master",
"twbs/bootstrap": "v3.2.0",
"knplabs/knp-paginator-bundle": "dev-master",
"knplabs/knp-menu-bundle": "dev-master",
"craue/formflow-bundle": "dev-master",
"friendsofsymfony/user-bundle": "~2.0#dev",
"liuggio/excelbundle": "~2.0",
"excelwebzone/recaptcha-bundle": "~2.3",
"robertotru/to-inline-style-email-bundle": "dev-master",
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "dev",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
}
},
"require-dev": {
}
}
[EDIT]
Specified require doctrine version.
I also have the feeling that this composer.json needs to be cleaned up somehow but that's another question...
Your problem seem to come from this strict restriction on the dependency : "doctrine/doctrine-bundle": "1.2.*" which require "doctrine/orm" < 2.5 (see here : https://packagist.org/packages/doctrine/doctrine-bundle#v1.2.0)
The solution might be to upgrade the version of this first dependency to
"doctrine/doctrine-bundle": "^1.6"
I didn't check the compatibility with all others packages so i'm not completly sure but you still can try.

Resources