Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda