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

Wrong autocompletion for Carbon::createFromFormat return value type #1857

Closed
ghost opened this issue Aug 19, 2019 · 2 comments
Closed

Wrong autocompletion for Carbon::createFromFormat return value type #1857

ghost opened this issue Aug 19, 2019 · 2 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Aug 19, 2019

Hello,

I encountered an issue with the following code:

$normalizedDateTime = Carbon::createFromFormat('Y-m-d H:i:s', $datetime, 'UTC');

Carbon version: 2.23.1

PHP version: 7.2.19-0ubuntu0.18.04.2

I expected to get:

Autocompletion in PhpStorm for $normalizedDateTime as Carbon instance

But I actually get:

Autocompletion in PhpStorm for $normalizedDateTime as DateTime instance.
So, to fix this issue, I suggest to add this line to PHPDoc section of Carbon/Carbon class:
 * @method static Carbon         createFromFormat($format, $time, $tz = null)

Thanks!

@kylekatarnls
Copy link
Collaborator

Hi,

The PHPDoc is properly set in CarbonInterface and the trait Creator we should not add one more @method which should be used only for magic methods.

I need first to check why PHPStorm fallback to the DateTime doc skipping the Carbon's one.

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Aug 30, 2019

Will be released in 2.24.0

jpmaga added a commit to jpmaga/Carbon that referenced this issue Jan 5, 2020
* Unbind $this in macros only for PHP < 8

* Privatize loadMixin* method as reserved for mixin() method

* Temporary disabling binding $this/static for PHP 8

* Set specific tests for each macros in PHP 7 and 8

* Persian language localization fixes

* Update Persian translations unit tests

* Update uz_Arab and mzn translations unit tests

* Fix briannesbitt#1816 from now translation in Chinese

* Update zh tests

* Add explicit imports and update composer description

* Cleanup PHPDoc

* Cleanup PHPDoc

* briannesbitt#1782 Fix from_now translation in Chinese

* Add comparison methods for CarbonPeriod bounds

* Add PHPDoc comments

* Allow string and interval in floor, round and ceil

* Implement carbonize() method get a Carbon date from interval/period/any

* Add rounding methods to CarbonInterval/CarbonPeriod

* Fix PHPDoc and add tests

* Fix PHPDoc for Carbon rounding methods

* Fix self references

* Add tests

* Add cast() method and traits mixins to CarbonInterval and CarbonPeriod

* Allow static methods in mixin traits

* Update CarbonInterface PHPDoc

* briannesbitt#1822 Use less short variants for short units in Polish

* Make zh_HK and zh_TW extend Hant/Hans

* Implement contains() and JsonSerializable in CarbonPeriod

* Implement new methods in CarbonPeriod
  - getIncludedStartDate()
  - getIncludedEndDate()
  - follows()
  - isFollowedBy()
  - isConsecutiveWith()

* Simplify duplicate code

* [Travis-CI] Simplify xdebug settings

* Mute deprecation notice

* Ignore mutability in equalTo comparison of periods

* Fix unit tests

* Fix typo

* Fix getIncludedEndDate

* Improve any native PHP classes and sub-classes as cast

* Fix briannesbitt#1831 Refresh global translator caching

* Add cast tests

* Take recurrences DatePeriod incrementation into account

* Mute type wrong PHPStan detections in tests

* Fix briannesbitt#1834 language detection in Lumen

* Make zh_Hans inherit from zh_Hant

* Add altNumbers option to forHumans/diffForHumans

* Fix alternate numbers in hours

* Ensure consistent output typing

* Add tests for altNumbers option briannesbitt#1817

* Fix briannesbitt#1837 fixed from_now translation in Fnnish and add few seconds

* briannesbitt#1837 Update Finnish tests

* Fix briannesbitt#1840 add short form or year for year in Turkish

* Update Turkish unit tests

* Fix PHP 8 compatibility

* Add doc for setDate()

* briannesbitt#1837 Add translation author

* Fix setISODate PHP 8 signature compatibility

* Implement methods that change of signature in PHP 8

* Allow null in __set_state for compatibility with PHP 8

Possible error to fix in PHP:
php/php-src#4526

* Remove temporary fix as fixed in PHP itself:
php/php-src@b17957e

* Remove obsolete tests

* Allow PHP 8 tests to fail until new PHP build is released

* Add test for setISODate()

* Fix Chinese Hant/Hans and meridiem

* [AR] Update with enhancements

* More enhancements

* Update files and fixing test unit

* Fix StyleCI issues

* Fix briannesbitt#1851 Update all Carbon classes on Laravel locale change

* Remove irrelevant test

* Fix PHP 8 compatibility

* Use require everywhere instead of include

* Implement briannesbitt#1856 Allow strings in isSame* methods

* Update PHPDoc and add tests

* Fix 1860 Allow Closure in setTestNow()

* Add create() test in Carbon::setTestNow()

* Fix briannesbitt#1861 Add aUnit option in Thai

* briannesbitt#1861 Add @nithisa authorship

* Allow to control timezone in testNow Closure

* Add PHPDoc

* Synchronize CarbonPeriod and CarbonInterval with Laravel locale

Thanks to @craig-sen to point out this

* Simplify swap expressions

* Reset language for all classes before running Laravel locale test

* Improve period/interval string detection in Carbon::make()

This allows to use make() with customized parse() methods

* Fix briannesbitt#1842 Latvian declension, aUnit and short units

* Add previous author complete name

* Fix zh locales merging

* Remove irrelevant zh_MO overrides

* Corrected sl-SI

* briannesbitt#1828 Make spaces around numbers consistent (both sides or none)

* briannesbitt#1824 Fix interpolations precedence and ordering

* Add missing tests

* Fix code style

* Update Slovenian unit tests

* Apply ago/from_now/before/after declension in multi-parts diffs

* briannesbitt#1849 Add Slovenian short units and "from now" declension

* briannesbitt#1800 Fix Lithuanian declensions

* briannesbitt#1800 Update Lithuanian tests

* briannesbitt#1800 Add Lithuanian calendar and ordinal numbers translations

* briannesbitt#1800 Fix Lithuanian year nominative 11+ plural

* briannesbitt#1800 Decline after translations like from_now ones

* briannesbitt#1800 Fix units plural

* briannesbitt#1857 Fix static methods typing autocompletion

* Add recurrences support in Carbon::toPeriod()

* Fix code style

* briannesbitt#1814 Remove error muter

* Fix briannesbitt#1877 Support timezone short offset format

* Nit: Grammar (briannesbitt#1880)

https://writingexplained.org/a-vs-an-difference

* Use static notation for called class

* Allow to get context from macros using self::this()

* Add missing import

* Remove typehint specificity

* Fix isBefore documentation

There was an error in the documentation of the function isBefore.

2018-07-25 12:45:16 is before 2018-07-25 12:45:18.

* Fix briannesbitt#1886 Support slashes in hasFormat()

* briannesbitt#1886 Add hasFormat() tests

* briannesbitt#1889 Fix Belarusian units translations

* briannesbitt#1893 Fix hour translation to година

* briannesbitt#1889 Fix Belarusian aUnit option translations

* briannesbitt#1893 Fix hour Ukrainian units translations

* briannesbitt#1889 Fix Belarusian aUnit option translations tests

* Add translation authors

* Fix briannesbitt#1902 Make hr_BA inherit hr language

* Replace $this with CarbonInterface in PHPDoc (briannesbitt#1904)

* Replace $this with CarbonInterface in PHPDoc
* [PHPStan] Ignore Carbon interface to instances mismatch

* Fix briannesbitt#1910 seconds Serbo-Croatian translation (briannesbitt#1911)

* Fix briannesbitt#1910 seconds Serbo-Croatian translation

* briannesbitt#356 Add toDateTimeLocalString precision parameter

* Add documentation for getTimeFormatByPrecision

* Add $unitPrecision parameters to relevant methods

Add $unitPrecision parameters to:
- toTimeString
- toDateTimeString
- toIso8601ZuluString

* Update PHPDoc

* Fixed all greater examples

Fixed bad one + changed date to have at least 1 true example

* Fix comparison examples

* Improve typings

* Apply fixes from StyleCI (briannesbitt#15)

* Fix typings

* Fix typehint for static create methods (Fix briannesbitt#1914)

* added new CreateFromFormat method to CarbonInterval

* fixed CarbonInterval::createFromFormat() dockblock

added example
fixed return type

* added CarbonInterval::createFromFormat() tests

* fixed tests inputs

* fixed tests testDefaults() and testNulls()

* Add diff translate

* Add option for rounding in forHumans

* Fix code style

* Implement custom interval formats parsing

* Fix too short variable name

* Use customizable factors for forHumans() rounding

* Add test for gap

* Use dedicated method to get the round factor

* Fix briannesbitt#1927 Finnish future interval translations

* Add rounding methods

* Implement FLOOR and CEIL options

* Fix code style

* Remove unused variable creation

* Remove unused method getRoundFactor

* Fix briannesbitt#1929 Indonesian from now translation

* Allow Symfony 5

* Show difference between FLOOR option and no option

* Fix briannesbitt#1908 Korean spacing and aUnit option

* Add 2.x-dev branch alias

* Added diff before_yesterday and after_tomorrow

* briannesbitt#398 Skip tests with easter_days() if ext-calendar is missing

* [Travis-CI] Remove unneeded dev dependency from the install

* Fix briannesbitt#1941 Symfony 5 compatibility

* Fix briannesbitt#1941 Replace Symfony custom rules with inline syntax

* briannesbitt#1941 Set me and scr locales as aliases

* Compare locales handling aliases

* Fix briannesbitt#1943 Add example for H:s.vi (briannesbitt#1944)

* Fix briannesbitt#1943 Add example for H:s.vi

* Fix briannesbitt#1943 Drop support of .v for PHP < 7.3

* Fix test PHP < 7.2 compatibility

* Add test for unit accumulation in interval rounding

* Fix briannesbitt#1949 Use format('T') to match ISO 8601 timezone format (briannesbitt#1950)

* Fix briannesbitt#1951 createFromTimestamp in DST chnge

* briannesbitt#1951 Add test for createFromTimestampMs

* [Travis-CI] Switch to PHP 7.4 stable release

* briannesbitt#1871 Improve translations using CLDR database (briannesbitt#1955)

* Fix briannesbitt#1953 Align Korean translation on CLDR (briannesbitt#1956)

* Fix briannesbitt#1954 Improvement from-now Armenian translation (briannesbitt#1957)

* Fix briannesbitt#1958 Standardize integer timezone input

* Fix briannesbitt#1958 Remove timezone auto-detection

* Fix PHPDoc alignment

* Add timezone unit tests

* Ease tests with OS locales dependency

* Fix briannesbitt#1968 Turkmen year and short days translations

* Added briannesbitt#1966 Tamil before and after translations

* Update Teso unit tests files

* Use CarbonInterface instead of self for Date trait constant as keys

* Speed up resetMessages

* Update PHPMD

* Add strict restrictions for translator requirements

* Fix Symfony 3 compatibility

* Fix month overflow sensibility of quarter tests

* Use common method for translators able to getLocale()

* Add unit tests for NotLocaleAwareException

* Fix method signature compatibility

* Use include instead of require to not stop the process if lang file is missing

* Fix briannesbitt#1970 Uzbek before/after translations

* Cleanup imports

* Fix briannesbitt#1977 Greek "ago" translation

Co-authored-by: Kyle <kylekatarnls@users.noreply.github.com>
Co-authored-by: Hassan Pezeshk <hpez58@gmail.com>
Co-authored-by: Mohamed Sabil <me@mohamedsabil83.com>
Co-authored-by: Gal Jakič <gal.jakic@gmail.com>
Co-authored-by: Arthur Cinader <700572+acinader@users.noreply.github.com>
Co-authored-by: Marc-Antoine Bouchard Marceau <marcantoine.bouchardm@gmail.com>
Co-authored-by: karlyn33 <karlyn33@users.noreply.github.com>
Co-authored-by: spaceemotion <spaceemotion@users.noreply.github.com>
Co-authored-by: silvio-gratani <42873063+silvio-gratani@users.noreply.github.com>
Co-authored-by: dima-bzz <dimabzz@gmail.com>
Co-authored-by: Tyler Collier <github@tylercollier.com>
Co-authored-by: Graham Campbell <GrahamCampbell@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant