Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Handle empty namespace prefixes #30

Merged
merged 2 commits into from
Jan 23, 2018
Merged

Fix: Handle empty namespace prefixes #30

merged 2 commits into from
Jan 23, 2018

Conversation

localheinz
Copy link
Member

@localheinz localheinz commented Jan 21, 2018

This PR

  • demonstrates a bug (or feature) with json_decode on PHP versions prior to 7.1
  • requires PHP 7.1

πŸ’β€β™‚οΈ According to https://getcomposer.org/doc/04-schema.md#psr-4 it's perfectly fine to use an empty namespace prefix as a fallback:

If you want to have a fallback directory where any namespace will be looked for, you can use an empty prefix like:

{
   "autoload": {
       "psr-4": { "": "src/" }
   }
}

However, this is a problem with json_encode() on versions prior to PHP 7.1.

See

Possible workarounds could be

  • use json_decode($json, true), but has consequences when $json contains empty objects/arrays as both will be interpreted as empty arrays
  • require PHP 7.1

@localheinz localheinz added the bug label Jan 21, 2018
@localheinz localheinz self-assigned this Jan 21, 2018
@soullivaneuh
Copy link

If the usage of json_decode is problematic with PHP 7.0, bumping to PHP 7.1 would the better choice IMHO.

Plus, it semver compliant and you are still under unstable 0.x versionning, so go for it! πŸ‘

@codecov
Copy link

codecov bot commented Jan 23, 2018

Codecov Report

Merging #30 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##             master    #30   +/-   ##
=======================================
  Coverage       100%   100%           
  Complexity       50     50           
=======================================
  Files             7      7           
  Lines           172    172           
=======================================
  Hits            172    172
Impacted Files Coverage Ξ” Complexity Ξ”
src/Normalizer/VersionConstraintNormalizer.php 100% <100%> (ΓΈ) 9 <0> (ΓΈ) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 4840417...69caa9d. Read the comment docs.

@localheinz
Copy link
Member Author

Thank you, @soullivaneuh!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants