How to convert this update script to PHP?

I'm having trouble converting this request to php :

POST candidates/_update/a23OcncBXBMGOH6pwXge
{
 "script": {
    "source": """
      if (ctx._source.containsKey('file')) {
        ctx._source.file.add(['filename':params.filename]); // adding a hash map -- could be any JSON primitive
      } else {
        ctx._source.file = [['filename':params.filename]]; // 1-member array
      }
    """,
    "params": {
      "filename": "abc"
    }
  } 
}

Here is my attempt :

$params = [

            'index' => 'candidates',

            'type'  => '_doc',

            'id'    =>  $file['candidate_id'],  

        ];

        $data = [

            'script' => [

                'source' => ("ctx._source.containsKey('file')" ? "ctx._source.file.add(params.data)" : "ctx._source.file = [params.data]"),

                'params' => [

                    'data' => $file

                ]

            ]

        ];

        $params['body'] = 

            $data

        ;

        $response = $client->update($params);

But it gives me this error :