codeclimate/codeclimate-duplication

Use of undefined constant NaN in JSON.php

borisceranic opened this issue · 4 comments

There is a problem that manifests itself as a PHP_NOTICE under certain conditions, such as when parsing certain PHP files. (I've already sent a support request for this with more details, via CodeClimate support.)

Notice looks like this:

PHP Notice:  Use of undefined constant NaN - assumed 'NaN' in /usr/src/app/vendor/php-parser/lib/PhpParser/Serializer/JSON.php on line 34

The problem is that the PHP constant NAN is spelled out incorrectly as NaN here: https://github.com/codeclimate/codeclimate-duplication/blob/master/vendor/php-parser/lib/PhpParser/Serializer/JSON.php#L34

Can anyone take a look at this?

Thanks for the report.

Are you able to provide a source file that, when analyzed, would reproduce the notice?

Error was discovered because duplication engine was scanning PEAR Horde_Text_Diff library, included in the forum software that we're using.

Steps to reproduce:

  1. Download Horde_Text_Diff v1.0.0alpha1 or v1.0.0alpha2 from
    https://pear.horde.org/ (wget https://pear.horde.org/get/Horde_Text_Diff-1.0.0alpha2.tgz)
  2. Unpack, enter folder (tar fvxz Horde_Text_Diff-1.0.0alpha2.tgz && cd Horde_Text_Diff-1.0.0alpha2/Horde_Text_Diff-1.0.0alpha2)
  3. Initialize CodeClimate (codeclimate init)
  4. Run analysis with duplication engine (CODECLIMATE_DEBUG=1 codeclimate analyze -e duplication)

You should take a look at file Diff/Engine/string.php found within this archive. Looks like it contains high-ASCII character(s), which confuses UTF-8 detection.

Environment:

$ docker image ls | grep codeclimate
codeclimate/codeclimate                  latest              39a41d180396        7 days ago          103MB
codeclimate/codeclimate-duplication      latest              3dac4fe33192        7 days ago          331MB
codeclimate/codeclimate-eslint           latest              71f96c20e669        7 days ago          399MB
codeclimate/codeclimate-eslint           <none>              1b83fd42475f        2 weeks ago         399MB
codeclimate/codeclimate                  <none>              31f7ebaa0555        2 weeks ago         104MB
codeclimate/codeclimate-phpcodesniffer   latest              7b7d9b1e4891        5 weeks ago         44.8MB
codeclimate/codeclimate-phpmd            latest              3f46f8e1efd0        7 weeks ago         38.7MB
codeclimate/codeclimate-eslint           eslint-3            c4b63cd2074d        7 weeks ago         407MB
codeclimate/codeclimate-scss-lint        latest              d5d3f217ce33        8 weeks ago         35.8MB
codeclimate/codeclimate-eslint           eslint-1            d618253c6fd0        2 months ago        120MB
codeclimate/codeclimate-fixme            latest              795165860666        4 months ago        212MB
codeclimate/codeclimate-eslint           eslint-2            d1c518a3d0f4        4 months ago        298MB

@borisceranic thanks so much for the thorough report. We just shipped an update for this. I'm going to close the issue, but please let me know if you have any other issues

@maxjacobson I can report that we are not encountering erroneous behavior with duplication engine any longer. Cheers and thank you!