Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
PHPDoc - Dynamic Function Names and Return Types for IDE

I'm working on (somebody else's) application. I'm not sure what framework it uses if any, but it allows calls like this

Users:findByUsername('josh');

Which will return one instantiated User object/entity that matches that username. This seems to be being done by overriding __callStatic. Not an enormous fan, but would like the IDE to recognize the variable as a User object (or whatever class it's being called from).

Very ideally, I'd like the IDE to recognize that as a valid function or an alias of callStatic, but that's not a big deal.

So is there anyway to PHPDoc findByX as a wildcard? Or a better way to do it? The call static function is as follows:

    public static function __callStatic($name, $arguments)
    {
        if (substr($name, 0, 6) == 'findBy') {

            $turn_off_date_filters = (isset($arguments[1]) && is_bool($arguments[1]) && $arguments[1] === true);
            $additional_params = (isset($arguments[1]) && is_array($arguments[1]))
                ? $arguments[1]
                : [];

            $filter = array_merge(
                $additional_params,
                [\Helper::camel2snake(substr($name, 6)) => $arguments[0]]
            );

            if ($turn_off_date_filters) {
                $entity = static::where($filter)->withoutActiveDateFilters()->withoutAvailabilityDateFilters()->first();
            } else {
                $entity = static::where($filter)->first();
            }

            return $entity;

        } elseif (substr($name, 0, 9) == 'findAllBy') {

            $additional_params = (isset($arguments[1]) && is_array($arguments[1]))
                ? $arguments[1]
                : [];

            $filter = array_merge(
                $additional_params,
                [\Helper::camel2snake(substr($name, 9)) => $arguments[0]]
            );

            return static::where($filter)->select();

        } elseif (substr($name, 0, 5) == 'where') {

            return static::where([\Helper::camel2snake(substr($name, 5)) => $arguments[0]]);

        } elseif (substr($name, 0, 11) == 'deleteAllBy') {

            return static::deleteAllBy([\Helper::camel2snake(substr($name, 11)) => $arguments[0]]);
        }

        return null;
    }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!