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

Incorrect type on Source->timestamp #1099

Open
moseslecce opened this issue Jan 16, 2025 · 0 comments
Open

Incorrect type on Source->timestamp #1099

moseslecce opened this issue Jan 16, 2025 · 0 comments

Comments

@moseslecce
Copy link

moseslecce commented Jan 16, 2025

The PHPDoc type for the field $timestamp is set as int in Smarty\Template\Source, however there are many examples that exist which set the timestamp to false in the event that there is no source file found.

Here are some notable examples:

src/Resource/StringEval

public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
 {
    $source->uid = sha1($source->name);
    $source->timestamp = $source->exists = true;
 }

src/Resource/StreamPlugin

public function populate(Source $source, ?Template $_template = null) {
    $source->uid = false;
    $source->content = $this->getContent($source);
    $source->timestamp = $source->exists = !!$source->content;
}

src/Resource/FilePlugin

public function populate(Source $source, ?Template $_template = null) {
    $source->uid = sha1(
        $source->name . ($source->isConfig ? $source->getSmarty()->_joined_config_dir :
        $source->getSmarty()->_joined_template_dir)
     );

    if ($path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig)) {
         if (isset($source->getSmarty()->security_policy) && is_object($source->getSmarty()->security_policy)) {
            $source->getSmarty()->security_policy->isTrustedResourceDir($path, $source->isConfig);
        }
        $source->exists = true;
        $source->timestamp = filemtime($path);
    } else {
        $source->timestamp = $source->exists = false;
    }
}

If this is intended, the type should likely be changed to int|false.

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

No branches or pull requests

1 participant