Skip to content

Commit df102cf

Browse files
author
Jonathan D.A. Jewell
committed
Auto-commit: Sync changes [2026-02-18]
1 parent 6aeddd5 commit df102cf

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/Sanctify/Transform/Sanitize.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Data.Text (Text)
3030
import qualified Data.Text as T
3131

3232
import Sanctify.AST
33+
import Sanctify.WordPress.Constraints (isWpdbObject)
3334

3435
-- | Context for output escaping
3536
data EscapeContext
@@ -255,16 +256,16 @@ transformModernizeCrypto file = file { phpStatements = map (mapStatement moderni
255256

256257
modernizeNode loc@(Located pos expr@(ExprCall callee args)) =
257258
case functionName callee of
258-
Just fn | fn == "rand" -> Located pos $ ExprCall (makeConst "random_int") (map updateArg args)
259-
| fn == "md5" -> Located pos $ ExprCall (makeConst "hash") (Argument Nothing (Located pos $ ExprLiteral $ LitString "sha3-256") False : map updateArg args)
260-
| fn == "sha1" -> Located pos $ ExprCall (makeConst "sodium_crypto_generichash") (map updateArg args)
259+
Just fn | fn == "rand" -> Located pos $ ExprCall (makeConst pos "random_int") (map updateArg args)
260+
| fn == "md5" -> Located pos $ ExprCall (makeConst pos "hash") (Argument Nothing (Located pos $ ExprLiteral $ LitString "sha3-256") False : map updateArg args)
261+
| fn == "sha1" -> Located pos $ ExprCall (makeConst pos "sodium_crypto_generichash") (map updateArg args)
261262
_ -> loc
262263

263264
modernizeNode loc = loc
264265

265266
updateArg (Argument name value unpack) = Argument name (modernizeExpr value) unpack
266267

267-
makeConst name = Located pos $ ExprConstant $ QualifiedName [Name name] False
268+
makeConst p name = Located p $ ExprConstant $ QualifiedName [Name name] False
268269

269270
functionName (Located _ (ExprConstant (QualifiedName parts _))) = Just $ unName $ last parts
270271
functionName _ = Nothing
@@ -324,7 +325,7 @@ mapStatement f (Located pos stmt) = Located pos (case stmt of
324325
StmtContinue n -> StmtContinue n
325326
StmtEcho exprs -> StmtEcho (map f exprs)
326327
StmtGlobal vars -> StmtGlobal vars
327-
StmtStatic pairs -> StmtStatic (map (ib -> (fst fib, fmap f (snd fib))) pairs)
328+
StmtStatic pairs -> StmtStatic (map (\(var, mexpr) -> (var, fmap f mexpr)) pairs)
328329
StmtUnset exprs -> StmtUnset (map f exprs)
329330
StmtDeclare decls body -> StmtDeclare decls (map (mapStatement f) body)
330331
StmtNoop -> StmtNoop)

src/Sanctify/Transform/TypeHints.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import qualified Data.Text as T
2121
import Data.Maybe (fromMaybe, mapMaybe)
2222

2323
import Sanctify.AST
24-
import Sanctify.Analysis.Types
24+
import Sanctify.Analysis.Types (TypeContext, emptyTypeContext, InferredType)
2525

2626
-- | Add type hints to function parameters based on defaults and usage
2727
addParameterTypeHints :: TypeContext -> Declaration -> Declaration
@@ -257,3 +257,11 @@ addAllTypeHints ctx file = file
257257
addMethodReturnHint c meth@MemberMethod{methReturn = Nothing, methBody = Just body} =
258258
meth { methReturn = inferReturnType c body }
259259
addMethodReturnHint _ meth = meth
260+
261+
-- | Run the type hint inference pipeline on a PHP file
262+
transformAddTypeHints :: PhpFile -> PhpFile
263+
transformAddTypeHints = addAllTypeHints emptyTypeContext
264+
265+
-- | Apply all type hint transformations with a fresh context
266+
transformAddTypeHints :: PhpFile -> PhpFile
267+
transformAddTypeHints = addAllTypeHints emptyTypeContext

test/SecuritySpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Sanctify.Parser
99
import Sanctify.Analysis.Security
1010
import Sanctify.Analysis.Advanced
1111
import Sanctify.WordPress.Security
12+
import Sanctify.AST (Located)
1213

1314
spec :: Spec
1415
spec = do

test/TransformSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Sanctify.AST
1010
import Sanctify.Emit
1111
import Sanctify.Transform.Sanitize
1212
import Sanctify.Transform.Strict
13-
import Sanctify.Transform.TypeHints
13+
import Sanctify.Transform.TypeHints (transformAddTypeHints)
1414

1515
spec :: Spec
1616
spec = do

0 commit comments

Comments
 (0)