smarty-php / smarty-php/smarty

Incorrect type on Source->timestamp

Open
#1,099 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the PHPDoc for $timestamp in Smarty\Template\Source and compare it with the populate methods in src/Resource/StringEval, src/Resource/StreamPlugin, and src/Resource/FilePlugin. Update the documented type if the false value is intended, then run the relevant existing test suite to verify the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.